I'm trying to set up NestJS-I18n to work with views created with Handlebars. I followed the quickstart guide, and orchestrated the translations as instructed. the dir-tree looks like this: src/i18n ├── en │ └── en.json └── fr └── fr.json
My appModule.ts:
I18nModule.forRoot({
fallbackLanguage: 'en',
loaderOptions: {
path: join(__dirname, '/i18n/'),
watch: true,
logging: true,
},
resolvers: [
{ use: CookieResolver, options: ['locale'] },
AcceptLanguageResolver,
],
viewEngine: 'hbs',
}),
I'm trying to use it in the controller like this:
@Get()
@Render('login-username')
login(@I18n() i18n: I18nContext, @Res() res: Response) {}
The relevant part of the html looks like this:
<div class="title" id="auth-sign-in-title">{{ t 'SIGN_IN' }}</div>
I keep getting an error message:
2024-02-26 15:32:01 error: Translation "SIGN_IN" in "en" does not exist. {"context":"I18nService","stack":[null],"timestamp":"2024-02-26T13:32:01.216Z"}
if I'm changing my html to
<div class="title" id="auth-sign-in-title">{{ t 'en.SIGN_IN' }}</div>
it works just fine. BUT - I don't want to hardcode the language, as it misses the purpose of using the library.
I'm not sure what I'm doing wrong, but for some reason it just doesn't work. Any insights?
Any help is much appreciated.