Closed amrelshinawy1 closed 4 years ago
Can you show me your project setup and structure?
src -
i18n-
en-
test.json
modules-
demo-
demo.controller.ts
app.module.ts
can you also show me your app.module.ts?
here is the app.module.ts
import { Module } from "@nestjs/common";
import { CoreModule } from "./core";
import { DemoModule } from "./modules/demo/demo.module";
import { I18nModule, QueryResolver, HeaderResolver } from "nestjs-i18n";
import { join } from "path";
@Module({
imports: [
CoreModule,
DemoModule,
I18nModule.forRoot({
path: join(__dirname, "./i18n/"),
fallbackLanguage: "en",
filePattern: "*.json",
resolvers: [new QueryResolver(["lang", "locale", "l"]), new HeaderResolver()],
saveMissing: true,
}),
],
})
export class AppModule {}
@amrelshinawy1 can you do a console.log(join(__dirname, "./i18n/"))
before the @Module
and send me the output?
@amrelshinawy1 also send me the contents of test.json
\dist\i18n\
test.json
{
"HELLO": "Hello",
"PRODUCT": {
"NEW": "New Product: {name}"
},
"ENGLISH": "English",
"ARRAY": [
"ONE",
"TWO",
"THREE"
],
"cat": "Cat",
"ONLY_EN_KEY": "this key only exists in en lang"
}
@amrelshinawy1 did you copy you i18n
folder to you dist
folder?
Try this path in development:
path: join(__dirname, "../src/i18n/")
yes i added i18n folder to the dist
also this path: join(__dirname, "../src/i18n/") didnt work
@amrelshinawy1 can you zip your project or send me the repo so I can test it myself? It's kind hard to debug this way :p
@amrelshinawy1 I downloaded your zip and started the server.
I went to http://localhost:7000/api/demo/
and it shows me Hello
as it should! So I can reproduce this error. If you can give me exact instructions how to reproduce this issue I can help you.
I'm going to close this for now.
yes it worked also with me maybe after i removed nodemodules thank you
We had the same problem. Turned out that the promise in parse.ts
was rejected due to:
https://github.com/ToonvanStrijp/nestjs-i18n/blob/241ec1003726be39a4577b6c5a0d472b241536a7/src/lib/utils/parse.ts#L17
isFile
seems to be undefined in Node 8. And we are still using Node 8 in production. But its time to switch I think. Nevertheless but you should wrap a try catch
around some Node file handling and reject with a meaningful error. That is the reason that it logs an empty object...
@amrelshinawy1 Did you switch to Node > 8 when your error was disappearing?
I can make a pull request by the way...
@loxy feel free to create a pull request! If you can make it backwards compatible with Node 8 would be great! (I can configure travis to test node 8 as well).
@loxy I'm working on a fix right now so you don't need to create a pull request ;)
Ok, nice!
@loxy fixed and released in V4.1.3! :tada:
TypeError: Cannot read property 'test.HELLO' of undefined at I18nService.translate (E:\elephant-tech\projects\theelephanttech-backend-boilerplate\node_modules\nestjs-i18n\dist\services\i18n.service.js:48:49)
and when theapplication start i got this [Nest] 14632 - 11/13/2019, 9:00:12 PM [I18nService] Object: {}