Replies: 3 comments
-
Looks like the compiler also default to id... So even when I use a custom formatter and clear out the id as a translation, the compilation falls back again. This is really frustrating. |
Beta Was this translation helpful? Give feedback.
-
Both examples are misuse of a library. The {i18n._({
id: "id1",
} || i18n._({
id: "id2",
})} Just have no sense, because if you know that Also "dynamically" provided by user
The interpolation for user messages will not work. If you want to use without interpolation, so it's easy as
|
Beta Was this translation helpful? Give feedback.
-
I ended up doing something like this: t(i18n)({
id: "id1",
message: `${label}`
}) OR
Which in the translation produces I know the messages have to be compiled. We plan to compile the user's input and combine them with precompiled system language. User provided language translations is essential. Our system isn't static and has user generated content. The reason for this use-case (tweaked a bit for clarity): {i18n._({
id: "id",
message: "default translation for instance"
} || i18n._({
id: "id/" + instanceId,
})} The default translation So I actually found a way to satisfy this use-case by wrapping I18n in a Proxy and I check for |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
The id is stored in the localization file. If you remove it manually, it falls back to id in
i18n._
. If your message is a variable, Lingui refuses to use it.To Reproduce
OR
In either case the extractor sees message as
""
, so it falls back to id.Then if you manually remove it from the file (which it will store again on next run because it sees it as empty), this line falls back to id again:
https://github.com/lingui/js-lingui/blob/main/packages/core/src/i18n.ts#L234
Expected behavior
I expect to be able to use a dynamic value as a fallback.
Additional context
I have pre-localization values that are user provided. They are basically custom text field labels. For this particular id the localization value will always be empty
""
. When it is empty it should fall back to the pre-localization value (without error).What we are planning to do is provide a localization section where the user can override specific labels for a specific localization. The pre-localization is essentially what we would consider the user's "base language".
Proposed Solution
Do not fall back to id for extract, and do not fall back to id in
i18n._
.This should be possible but currently isn't because
i18n._
always returns a non""
value.Perhaps consider checking for
undefined
instead of falsy so you could do something like this as a compromise:Beta Was this translation helpful? Give feedback.
All reactions