opral / monorepo

globalization ecosystem && change control SDK
https://opral.com
Apache License 2.0
1.17k stars 98 forks source link

[Paraglide] Language Fallbacks #1949

Closed LorisSigrist closed 9 months ago

LorisSigrist commented 9 months ago

Continuation from: #1728

Problem

Currently, when the current language doesn't have a given message undefined is returned.

This is an issue for a few reasons:

You can catch missing messages using the lint rule, but paraglide should work independently of which lint rules are configured.

Proposal

Define a default fallback order & substitute messages from other languages if they are missing in the current language.

I would propose the following order:

  1. Exact match: de-CH-ZH
  2. Regional in descending specificity: de-CH then de
  3. Source Language: en

This should guarantee that there is always some message that can be shown to users. For the moment I wouldn't make the fallback order configurable, we can always add that in the future.

LorisSigrist commented 9 months ago

As for the implementation, I would propose to add an export { missing_message_id } from "./{fallbackLang}.js" statement in the language module. This should fully treeshake & minify away if both the language and fallback language are loaded.

@samuelstroschein sound good?

LorisSigrist commented 9 months ago

If there is a scenario where there are sibling languages from the same region (eg de-CH and de-DE) but not the region itselft (eg de is not available), should we use the sibling before the source language?

This seems like a reasonable fallback.

The full order would be:

  1. Exact match: de-CH-ZH
  2. Regional in descending specificity: de-CH then de
  3. In ascending Tree-Traversal distance starting from exact match within the region (within de) : de-DE, de-DE-bavarian
  4. Source Language: en

If the source-language tag get's found before hitting condition 4, then the search stops

samuelstroschein commented 9 months ago

I propose to implement the fallback algorithm in @inlang/language-tag according to the BCP-47/RFC-4647 spec. Paraglide just just follow the language negotiation spec from @inlang/language-tag and call it a day. Language negotiation (fallbacks) will be a never-ending story. If we "follow the spec", we and the ecosystem already won.

LorisSigrist commented 9 months ago

Sounds good. I'll implement it according to the spec

samuelstroschein commented 9 months ago

I would postpone this issue until it becomes pressing. I don't see how this will contribute to growth in the short run