Skip to content

Is it possible to dynamically choose language? #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MasterGroosha opened this issue Aug 17, 2020 · 4 comments
Closed

Is it possible to dynamically choose language? #153

MasterGroosha opened this issue Aug 17, 2020 · 4 comments

Comments

@MasterGroosha
Copy link

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
Copy link
Contributor

Pike commented Aug 17, 2020

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.

@MasterGroosha
Copy link
Author

@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
Copy link
Contributor

Pike commented Aug 21, 2020

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

@MasterGroosha
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants