toonvanstrijp / nestjs-i18n

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

Translations are removed when args are not present #632

Open kashyap-aditya opened 6 months ago

kashyap-aditya commented 6 months ago

Describe the bug

let translatedText: T = await this.i18nRequestScopedService.translate("CAT_NAME", { lang: 'en-us', });

key points to a json file with this: "CAT_NAME": "My cats name is {name}"

In v8.3.0, the returned text is : "My cats name is {name}" In v8.3.1, the returned text is: "My cats name is {}"

I am quite confident that the issue is because in i18n.service.ts, there is a line: const args = options?.args ?? {};

but because of that, even when the passed in options.args is undefined, it gets set to {} and hence the second part of the following boolean always translates to true: if (translation && (args || (args instanceof Array && args.length > 0)))

Reproduction

let translatedText: T = await this.i18nRequestScopedService.translate("CAT_NAME", { lang: 'en-us', }); key points to a json file with this: "CAT_NAME": "My cats name is {name}" In v8.3.0, the returned text is : "My cats name is {name}" In v8.3.1, the returned text is: "My cats name is {}" I am quite confident that the issue is because in i18n.service.ts, there is a line: const args = options?.args ?? {}; but because of that, even when the passed in options.args is undefined, it gets set to {} and hence the second part of the following boolean always translates to true: if (translation && (args || (args instanceof Array && args.length > 0)))

System Info

node 18.20.2

Used Package Manager

npm

Validations

rubiin commented 6 months ago

Can you try the latest?

kashyap-aditya commented 6 months ago

Can you try the latest?

I can't without breaking my company's codebase. There are breaking changing in the latest version. I actually think it was fixed in V9.1.6 https://github.com/toonvanstrijp/nestjs-i18n/pull/369

But I am wondering if it would be possible to create a version 8.3.3 with this fix?