i18n icon indicating copy to clipboard operation
i18n copied to clipboard

Allow overriding translations

Open rayz1065 opened this issue 1 year ago • 4 comments

For some use-cases it would be useful to have the ability to override certain translations programmatically, for example by loading multiple translation files before loading the default translations.

This is currently not possible since the matchBundles in src/fluent.ts only allows matching a single bundle per locale.

Current behavior

  • the default locale is en
  • bot tries to translate "hi" into locale it;
  • "hi" is not present in the override file;
  • bot falls back to the default bundle with locale en.

Desired behavior

What I would like to happen is for the bot to first try finding the translation in the other files of locale it. Adding this behavior only requires changing how bundles are matched. It also does not break any test, as having multiple bundles for a single locale was previously unsupported.

rayz1065 avatar Jul 10 '24 09:07 rayz1065

This sounds like what you really want is to specify one locale in several files that all get merged. In other words, you want to split up the translation strings into several files per language. Is that correct?

KnorpelSenf avatar Jul 10 '24 09:07 KnorpelSenf

That would be the ideal behavior, but it would require properly handling warnings for messages missing in locales. I have a few ideas of how this could be implemented (for example firing the warning only when all the bundles for a locale have been exhausted) but I would like to hear your opinions about it.

rayz1065 avatar Jul 10 '24 10:07 rayz1065

Shouldn't the file handling and translation be separate? At least for my bots I read in all the fluent files at startup and translations then should be handled independently of the file system.

Before the rewrite to fluent this library used to check for a translation until there is one (user settings until default). Not sure how exactly the current implementation behaves.

EdJoPaTo avatar Jul 10 '24 15:07 EdJoPaTo

Shouldn't the file handling and translation be separate

Yes sorry I was a bit imprecise with my words, I meant to say that I would like the plugin to first iterate through all the bundles (not files) of the same locale before falling back to the default bundle.

rayz1065 avatar Jul 10 '24 18:07 rayz1065