My project structure is this:
root
├── backend (nest cli)
├── frontend
└── shared
└── translations
├── en.json
├── no.json
└── nl.json
I am trying to use 'nestjs-i18n'. Where their folder structure in the docs are:
...
src
└── i18n
├── en
│ ├── events.json
│ └── test.json
└── nl
├── events.json
└── test.json
Is it possible to implement this package following my language file structure? Its actually confusing in their documentation that if its required to follow their structure and the folder 'i18n'.
I have imported the module in app.module.ts :
@Module({
imports: [
I18nModule.forRoot({
fallbackLanguage: 'en',
loaderOptions: {
path: join(process.cwd(), '../shared/translations'),
watch: true,
},
resolvers: [TenantLanguageResolver],
}),
],
But whenever I'm trying to access it like this:
const trans = await i18n.t('roles_help_text');
Getting the error:
ERROR [I18nService] Translation "roles_help_text" in "en" does not exist.
nestjs-i18n doesn't provide the custom loader at present. So I have followed its strict file and folder naming structure. I haven't used any custom resolver to resolve language. Just added the language files in the assets array like the following:
// nest-cli.json
assets": [
{
"include": "../../shared/translations/en.json",
"watchAssets": true,
"outDir": "dist/i18n/en"
},
{
"include": "../../shared/translations/no.json",
"watchAssets": true,
"outDir": "dist/i18n/no"
}
]
Upon running the nest application, you will find the language files in the dist
folder like the nestjs-i18n package wants them to be, inside their own nested folders:
dist
└── i18n
├── en
│ └── en.json
│── no
└── no.json