toonvanstrijp / nestjs-i18n

The i18n module for nestjs.
https://nestjs-i18n.com
Other
655 stars 113 forks source link

ERROR [RpcExceptionsHandler] I18n context undefined #637

Open sg-milad opened 5 months ago

sg-milad commented 5 months ago

Describe the bug

I am trying to implement i18n in microservice. its works completely fine in HTTP requests but when I use it in my microservices I get this error gateway: [Nest] 579618 - 05/26/2024, 11:01:13 AM ERROR [ExceptionsHandler] Internal server error microservice app:

[Nest] 578651  - 05/26/2024, 11:00:19 AM   ERROR [RpcExceptionsHandler] I18n context undefined
I18nError: I18n context undefined
    at /home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/nestjs-i18n@10.4.5_@nestjs+common@10.2.10_@nestjs+core@10.2.10_class-validator@0.14.1_rxjs@7.2.0/node_modules/nestjs-i18n/src/decorators/i18n.decorator.ts:14:11
    at /home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/@nestjs+core@10.2.10_@nestjs+common@10.2.10_@nestjs+microservices@10.3.1_@nestjs+platform-exp_3itvyzrtyhpuen4ihidhhpk5f4/node_modules/@nestjs/core/helpers/context-utils.js:43:28
    at resolveParamValue (/home/sg-milad/Downloads/clone/igaming-platform-backend/prediction/node_modules/.pnpm/@nestjs+microservices@10.3.1_@nestjs+common@10.2.10_@nestjs+core@10.2.10_amqp-connection-mana_dmbtl4esns5bxhksz4zyh4cgji/node_modules/@nestjs/microservices/context/rpc-context-creator.js:105:31)
    at Array.map (<anonymous>)

// this my config in app.module gateway

       I18nModule.forRoot({
            fallbackLanguage: "en",
            loaderOptions: {
                path: join(__dirname, "/i18n/"),
                watch: true,
            },
            resolvers: [
                { use: QueryResolver, options: ["lang"] },
                AcceptLanguageResolver,
                new HeaderResolver(["x-lang"]),
            ],
            typesOutputPath: developmentEnv() ? path.join(__dirname, '../src/shared/generated/i18n.generated.ts') : undefined,
        }),
  app.connectMicroservice<MicroserviceOptions>(mainClientMicroservice(configService), { inheritAppConfig: true });
constructor(@Inject("somthing") private readonly client: ClientRMQ,) { }
    async getHello() {
        return await lastValueFrom<string>(this.client.send("hello", {}))
    }

and my microservice app:

@MessagePattern("hello")
    getHello(@I18n() i18n: I18nContext): string {
        return i18n.t("messages.hello")
    }

I use rabbitMq

Reproduction

please tell me if the the information i provided is not enough

System Info

System:
    OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (8) x64 AMD Ryzen 7 3700U with Radeon Vega Mobile Gfx
    Memory: 2.97 GB / 9.58 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.17.1 - /usr/local/bin/node
    npm: 10.2.5 - /usr/local/bin/npm
    pnpm: 8.7.1 - /usr/local/bin/pnpm
// my package.json
  "amqp-connection-manager": "^4.1.14",
   "nestjs-i18n": "^10.4.0",
  "amqplib": "^0.10.3",
nestjs version 10

Used Package Manager

pnpm

Validations

fromage9747 commented 4 months ago

I have the exact same issue. I thought I was executing code before the i18n module had loaded but if I manually hard code a language key into my code it works fine, so now I am passing the fallback language key as an environment variable as fallbackLanguage parameter is not working.