grammyjs / i18n

Internationalization for grammY powered by Fluent.
https://grammy.dev/plugins/i18n
MIT License
30 stars 6 forks source link

Allow overriding translations #48

Open rayz1065 opened 2 months ago

rayz1065 commented 2 months ago

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

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.

KnorpelSenf commented 2 months ago

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?

rayz1065 commented 2 months ago

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.

EdJoPaTo commented 2 months ago

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.

rayz1065 commented 1 month ago

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.