Skip to content
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

[FEAT] Translation like Style ? #456

Open
Kochise opened this issue Oct 13, 2021 · 3 comments
Open

[FEAT] Translation like Style ? #456

Kochise opened this issue Oct 13, 2021 · 3 comments

Comments

@Kochise
Copy link

Kochise commented Oct 13, 2021

Could there be a way to add translation capability, just like styling widgets ?

enamldef MyLocales(Locales):
	json = "translations.json"
	Locale:
		name = "French - France"
		lcid = "fr-fr"
		Translation:
			object_name = "lbl_def"
			text = "Texte par défaut"
	Locale:
		name = "German - Germany"
		lcid = "de-de"
		Translation:
			object_name = "lbl_def"
			text = "Standardtext"
		Translation:
			name = "str_out_of"
			text = "{} aus {}"
	Locale:
		name = "Latvian"
		lcid = "lv"
		Translation:
			from = "Default text"
			text = "Noklusejuma teksts"

enamldef Main(Window):
	title = 'Translation test'
	locale << my_loc.lcid_of(sel_loc.selected)
	MyLocales: my_loc:
		pass
	Container:
		padding = 0
		constraints = [vbox(lbl_def, sel_loc)]
		Label: lbl_def:
			text = "Default text"
		ObjectCombo: sel_loc:
			items = my_loc.locales()
			selected = my_loc.name_of("fr-fr")

The idea would be to provide either a JSON file containing basically the same structure, or specific translation (from widget's name) or generic translation (from widget's initial text, imply caching the original text). Setting locale to None indeed display the original text.

Now the question remains how to identify properly each locale, I think the LCID is best because universal, while the name also needs to be translated as well : https://www.loc.gov/standards/iso639-2/php/code_list.php

You can find locales identifiers here : https://www.science.co.il/language/Locale-codes.php / https://ss64.com/locale.html

https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes / https://iso639-3.sil.org/code_tables/639/data

Another question would be how to translate things like formatting strings (like "{} out of {}") easily. Maybe a my_loc.get_string('str_out_of') would do the trick.

@MatthieuDartiailh
Copy link
Member

Sounds like an interesting idea. I am quite swamped at the moment and won't have time to investigate this but if you want to make a PoC I will review any PR under the best delays.

@sccolbert
Copy link
Member

sccolbert commented Oct 13, 2021 via email

@Kochise
Copy link
Author

Kochise commented Oct 14, 2021

Pretty much "automated" translation without having to do a gettext by hand everywhere. Just like "theming" without having to change style by hand for every widget.

What had you in mind as for "3rd party internationalization library" ?

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

3 participants