Reputation: 2657
I found this package nest-18n
but that dudes thinks that nestjs is only used for api and not mvc.
So sure ?lang=en
or ?lang=de
works and it changes language but question is how to use that on view?
My first thought was that this is working out of the box with __("Something to translate")
. But that will not work (__ is undefined
).
Since i18Service.translate
method is async you can not add it to view (there is pug then
but that is horrible idea). Idea of adding anything on the the view that is async does not make sense at all. So in principle they made package that can not be used outside of api's.
Other thing that i can do is to have something like
class AppController extends BaseController() {
@Get("/")
index() {
return {
someTranslation: await this.getTranslation("give me something to translate"),
// IMAGINE NOW Having 1000 OF TRANSLATION ON INDEX PAGE
}
}
}
where BaseController
is:
class BaseController() {
constructor(private readonly i18n: I18nService, lang: string) {
}
async protected getTranslation(stringToTranslate: string) {
return await this.i18n(stringToTranslate, {lang});
}
}
Does anyone have idea how to use any of i18n in nestjs mvc?
Upvotes: 3
Views: 749