-
Notifications
You must be signed in to change notification settings - Fork 435
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
Feature request: Internationalization #103
Comments
I went through https://docs.flutter.dev/development/accessibility-and-localization/internationalization and it's a kind of scary how it's made on Flutter side. I'm thinking about approach on Python (app) side instead. Also, let's not forget that it's not only |
It's more than that Some languages are RTL, so the entire UI must be completely mirrored left and right, for example: Arabic Wikipedia or Openstreetmap in Hebrew Even font used can make things, CJK character share same unicode code but the should be different glyph, you need to detect using which set of font for different east asian language. What more frustrated its their fallback chain. |
I had created this app repo. I tried to translate the whole UI with translation files created by the py-auto-translate tool, which generates There is no problem with direction change, characters, etc, but it seems the texts are stored somewhere, perhaps in a cache, and are not being updated even after |
Now I found tricky way to internationalize application (for desktop and mobile only) with this code you can generate and use import os
import sys
from translation import set_current_language
import flet as ft
# Codes
class BaseView(ft.View):
"""Base View class for all views in application
"""
page: ft.Page
def __init__(
self,
page: ft.Page,
*args,
**kwargs) -> None:
super().__init__(*args, **kwargs)
self.padding = 0
self.expand = True
self.page = page
self.page.on_resize = self.on_resize
self.set_content()
def on_resize(self, event: ft.ControlEvent, *args, **kwargs):
self.page = event.page
self.set_content()
self.page.update()
def chlang(self, lang: str = "en", *args, **kwargs) -> None:
"""Change language to given language if language isn't provided it switchs to oposit language
Args:
lang (str, optional): language code. Defaults to English (en).
"""
set_current_language(page=self.page, lang=lang)
self.set_content()
def set_content(self):
pass Now when you press button to change language after changing it, it calls I'm not sure about Chinese/Korean/Japanese, but it works for languages such as English and RTL languages with Persian based glyph such as Arabic, Pashto, etc. You can work around code with |
Support showing UI in user's language.
This is not necessarily a "flet concern", as all the necessary machinery can be "on top" of the controls (e.g. Text control value is given by a function call that gets user's language and a message identifier as parameters, and returns the actual text to show in user's language).
But, it would be nice to have a shared/recommended way to implement this, instead of everyone rolling their own.
Python standard library provides gettext, which is used by heavyweights like Django.
We could even support automatic (and risky) batch translation to various languages, see e.g. this article.
The text was updated successfully, but these errors were encountered: