-
-
Notifications
You must be signed in to change notification settings - Fork 590
Description
Current behavior
Applications may provide translations that are already compiled, like:
const myEnTranslations = {
hello: () => "hello"
}
// assuming this runs in an injection context
function setTranslations() {
const translateService = inject(TranslateService);
translateService.setTranslation("en", myEnTranslations);
}This used to work on the previous version (v16), but it started breaking on the latest one (v17).
Expected behavior
It should be possible to pass compiled translations like before without any further adjustments.
How do you think that we should fix this?
This was caused by a refactoring in the type system. Nothing has changed at runtime, and the error can be potentially ignored with @ts-ignore or @ts-expect-error.
To fix this, in my eyes StrictTranslation should be extended to include InterpolatableTranslation:
Notice that this behavior is actually expected by default, in the sense that the default compiler is no-op:
As the comment suggests, in case there is no need for a compiler at all, i.e., in case someone has already compiled the translations beforehand.
Minimal reproduction of the problem with instructions
// 1. Create an object with string translation keys and functions as values.
const demoEnTranslations = {
"hello": () => "hello",
"hello-params": (params) => "hello" + params.world
}
// 2. Call `setTranslation` with the translations object defined above.
function setTranslations() {
const translateService = inject(TranslateService);
translateService.setTranslation("en", myEnTranslations);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// Argument of type [...] not assignable to 'TranslationObject'
}Environment
ngx-translate version: 17.0.0
Angular version: 21.0.3