projectfluent/python-fluent

Is it possible to dynamically choose language?

MasterGroosha opened this issue · 4 comments

Hello. I was going to use Fluent to add translations to my Telegram bot.
When a message arrives, my code gets user's language code to get a string on desired language.
However, I didn't find an option "get string in {language}" in Python-fluent.

Am I missing something? If there's no such feature, is it planned at all? I'm looking for a user-friendly gettext alternative, which support choosing language on-the-fly for any string.

Pike commented

We defer to applications for that level.

From an architecture POV, you want to cache Localization instances. And as with any cache, it's very application-specific when it's a good time to purge an entry from the cache.

@Pike Could you please provide a basic example how to change language on the fly?
I'm looking at https://www.projectfluent.org/python-fluent/fluent.runtime/stable/usage.html#using-fluentlocalization, but it doesn't show how to choose language while getting a string by key.

Pike commented

You would write a higher-level code that took care of that. At the level of the Localization class, you can't switch languages.

Thank you for the answer. I guess I must be looking for something else then.