introduce concept of system wide fallback logic #1267
Unanswered
ivanhofer
asked this question in
[inlang SDK] Feature Requests
Replies: 2 comments 2 replies
-
Alternative proposal - Use BCP-47 spec and contain logic in
|
Beta Was this translation helpful? Give feedback.
2 replies
-
i would make it easy. but i‘m not an expert. we already define refLanguage in the config. just use the ref as fallback. but using a spec already solving this issue is always the better solution. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
In real world applications there will be cases where not every Message get's translated to all languages. Some might not be important because e.g. features are hidden in certain markets or maybe because a feature needs to be shipped as soon as possible when translators didn't had the time to write all translations. In this cases having a fallback mechanism is important to not render empty strings in the UI.
The SDK requires such a functionality, but also the IDE extension could benefit from it so developers can see what will be rendered if a message is missing in a certain language. It also makes sense to include the fallback logic into the Editor so translators can also immediately see what text get's rendered.
Solution
So adding a new property to the root of the
inlang.config.json
would make sense.fallbackLanguageTag: FallbackLanguageTag
Options
We don't have to introduce all options for now, but
sourceLanguageTag
andnone
should be the options we support at the beginning.none
: No fallback variant get's rendered (empty string iflanguageTag
is missing)sourceLanguageTag
: Always falls back to thesourceLanguageTag
bestMatch
: Finds the first match in the users' preferred languages.sameLanguage
: if no exact match, it takes an variant from another country with the same language.Counts for all except
none
: If no match is found, thesourceLanguageTag
get's chosen.Should we make the option optionally an array? So people can mix strategies however they like e.g.
['sameLanguage', 'bestMatch']
.Alternative
Or maybe should a "Plugin" provide a fallback logic written in JS to also accomplish complexer scenarios?
We can provide 2-3 plugins with common fallback strategies and the rest is up to other developers.
Default
We can hide the option from the config and decide on a default value. But then we can't introduce the "better" variant at a later point because it would be a breaking change.
Anyways we need to come up with a default value.
Implementation
We should provide some utility functions each
app
can use to "enhance" themessages
returned from aplugin
. Maybe a variantlanguageTag: '*'
could be added to each message to mark it as the fallback. As each app will probably have minor differences I'm usure ifinlangProject
should do that already or if each app can decide if it needs to "enhance" all messages or just a single one.@inlang/team please discuss.
Beta Was this translation helpful? Give feedback.
All reactions