Allow changing the language dynamically #4295
tk-subgenius
started this conversation in
Ideas / Feature Requests
Replies: 1 comment 3 replies
-
Hi @tk-subgenius, There is, indeed, no official API for changing the language. Therefore I'll turn this question into a feature request. It would be nice if we could specify a list of languages like For now you can use the following workaround: from nicegui import __version__, ui
ui.add_body_html(f'''
<script src="/_nicegui/{__version__}/static/lang/de.umd.prod.js"></script>
<script src="/_nicegui/{__version__}/static/lang/fr.umd.prod.js"></script>
<script src="/_nicegui/{__version__}/static/lang/es.umd.prod.js"></script>
<script src="/_nicegui/{__version__}/static/lang/zh-CN.umd.prod.js"></script>
''')
def switch_language(language_code: str) -> None:
ui.run_javascript(f'''
Quasar.lang.set(Quasar.lang["{language_code.replace('-', '')}"])
''')
ui.select(options={
'de': 'Deutsch',
'en': 'English',
'fr': 'Français',
'es': 'Español',
'zh-CN': '中文',
}, value='en', on_change=lambda e: switch_language(e.value))
ui.date()
ui.run() The date element is just for demonstrating the effect of the selected language. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
Hi everyone! Please question, I'd like to change the language (including quasar components) based on logged-in user attributes. I see there is
ui.run(language='cs')
, but how to change the language dynamically inside a page, after ui.run is called? I dug around some and saw one comment it's possible from user code, but not officially via platform APIsBeta Was this translation helpful? Give feedback.
All reactions