transloco icon indicating copy to clipboard operation
transloco copied to clipboard

Feature(transloco): use fallback language for resolving referenced keys

Open Tlepel opened this issue 1 year ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Which Transloco package(s) will this feature affect?

Transloco

Is your feature request related to a problem? Please describe

We reference translations quite often using this method: https://jsverse.github.io/transloco/docs/additional-functionality#reference-other-keys

However, when a regional language is used, those keys don't use the fallback language.

Describe the solution you'd like

I think it would be nice if the transpiler would use the fallback language for referenced keys if the current language doesn't include the key.

Describe alternatives you've considered

Alternatives I've considered are for example duplicating the necessary keys, but that's not ideal since maintenance would become very tedious.

Another alternative is rejecting the use of regions, but that's not really likely.

Additional context

Let me know if there's any pointers as to whether there are consequences I haven't thought of, since to me it seems like this shouldn't impact any current implementations.

I would like to make a pull request for this feature

Yes 🚀

Tlepel avatar Jan 23 '24 10:01 Tlepel

I'm looking for exactly that. I thought setFallbackLangForMissingTranslation would do that, but it didn't. It'd be great to have a way to fallback to a specific provided language, if the key is not found in the current one. In my case, I register a lot of keys with the service in a library where the language is named en. In the consuming app, the language is named en-US. If the key is not present in en-US, I'd like transloco to get it from the fallback language, which doesn't seem to be happening today.

eestein avatar Sep 04 '24 20:09 eestein