Skip to content

Commit d371d16

Browse files
committed
🐛 add missing default locale handling for templates
1 parent 24aafad commit d371d16

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/notifications/templates/template-cache.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable, Logger, OnModuleInit } from "@nestjs/common";
22
import { readdirSync, readFileSync, statSync } from "fs";
33
import Handlebars from "handlebars";
44
import { basename, join } from "path";
5+
import { LANGUAGES } from "src/settings/entities/language.entity";
56

67
@Injectable()
78
export class TemplateCacheService implements OnModuleInit {
@@ -35,7 +36,17 @@ export class TemplateCacheService implements OnModuleInit {
3536
Logger.log('Initialized templates', TemplateCacheService.name);
3637
}
3738

38-
getTemplate(name: string, locale: string): Handlebars.TemplateDelegate|null {
39-
return this.templateMap.get(name)?.get(locale);
39+
getTemplate(name: string, locale: string = LANGUAGES.en): Handlebars.TemplateDelegate|null {
40+
const template = this.templateMap.get(name)?.get(locale);
41+
42+
if (template) {
43+
return template;
44+
}
45+
46+
if (locale !== LANGUAGES.en) {
47+
return this.templateMap.get(name)?.get(LANGUAGES.en) || null;
48+
}
49+
50+
return null;
4051
}
4152
}

0 commit comments

Comments
 (0)