Open armpogart opened 1 year ago
For translating nested translations without arguments, I'm not even sure how it's supposed to work. There is a part in the I18nService
that always checks for args before trying to translate nested translations:
the nested translations without args supposedly got fixed with #278 but I still have this same issue in 10.2.6:
// translations.json
{
"nestedValue": "world",
"foo": "Hello $t(translations.nestedValue)"
}
// foo.service.ts
i18n.translate("translations.foo", { args: {} }) // result: "Hello world"
i18n.translate("translations.foo") // result: "Hello $t(translations.nestedValue)"
🤔
Also just discovered this unit test which explicitly states that nested without args should return the template, not the actual translation: https://github.com/toonvanstrijp/nestjs-i18n/blob/main/tests/i18n-express.e2e.spec.ts#L565-L569
I think if there is a test for it that specifies that the nested translations without the args should return the template itself, then I suppose this is the desired implementation. To overcome this, you can always pass empty args like
i18n.translate("translations.foo", { args: {} }) // result: "Hello world"
@rubiin that would be a very odd expected behavior and is also nowhere documented. Also I am still wondering why #278 says it was fixed then, because it clearly wasn't (or at least not anymore).
@Susccy I think I will add this to documentation for now
I have project where I have 2 scenarios, which are both impossible as far as I see currently with this module:
telegraf
) and as far as I see there is no a way to get custom resolvers working with custom context. I wanted to have a resolver, which can get the language of the Telegram user from the context I have.nestjs-telegraf
, but resolvers again won't be called.Any way to implement custom context, and/or custom interceptor which will work for my cases?
P.S. The fallback solution for me now, is just use some language service, which will abstract away resolvers functionality and provide the
lang
directly from language service when usingI18nService
, but with that solution I can't get nested translations (without arguments) to work anyways. The nested keys are not getting translated at all.