Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Approach of implicitly setting fallback language considered harmful #14

Open
xdev1 opened this issue Jun 26, 2022 · 0 comments
Open

Approach of implicitly setting fallback language considered harmful #14

xdev1 opened this issue Jun 26, 2022 · 0 comments

Comments

@xdev1
Copy link

xdev1 commented Jun 26, 2022

[Edit] I've changed the following proposal to be as simple as possible


[README.md] "The first translation that's registered will be used as the fallback."

This may sounds quite pragmatic first, but in the end this approach has really severe problems:

  1. It's NOT possible for an app NOT to use a fallback language - at least not without doing some odd things like registerTranslation({ $code: '$$fake-fallback-lang$$', $name: '', $dir: 'ltr' }). In many apps, the supported languages are well-known and the document element's lang attribute will always be set properly by the app itself, so if a translation is NOT given, you do not want a "fallback", but an error message as this is just a bug which has to be fixed before the app will be published.

  2. Function registerTranslation is a violation of the "principle of least surprise". Normally, nobody would guess that a function called registerTranslation will also set the fallback language implicitly on certain conditions.

  3. Function registerTranslation is a violation of the "single-responsibility principle", it should only "register translations" and nothing else.

  4. The whole approach is quite invasive and its behavior sometimes hard to predict: Every file, every module, every library that uses registerTranslation may intentionally or unintentionally set the fallback language, like for example shoelace is doing it:

    [Shoelace doc] "Shoelace uses English as a fallback to provide a better experience than rendering nothing or throwing an error."

Possible solution:

Just use attribute data-fallback-lang on the <html ...> element to configure the fallback language (for example: <html lang="it" data-fallback-lang="fr">).
Something like this may work (not tested yet): Show diff

Default fallback language should be en (like already done for shoelace), to make the components show English texts as fallback by default.
<html lang="it-CH" data-fallback-lang="fr"> will set a different fallback language.
<html lang="it-CH" data-fallback-lang="none"> will not use any fallback language at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant