enaml icon indicating copy to clipboard operation
enaml copied to clipboard

[FEAT] Translation like Style ?

Open Kochise opened this issue 2 years ago • 3 comments

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.

Kochise avatar Oct 13 '21 16:10 Kochise

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.

MatthieuDartiailh avatar Oct 13 '21 16:10 MatthieuDartiailh

I don't see any benefit to this over using a 3rd party internationalization library, or the built-in gettext. What are you wanting to accomplish that can't be handled by those?

On Wed, Oct 13, 2021 at 11:59 AM Matthieu Dartiailh < @.***> wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/456#issuecomment-942507072, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSMVRVRPLLOD447RLNTUGW3HLANCNFSM5F5SYYCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

sccolbert avatar Oct 13 '21 19:10 sccolbert

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" ?

Kochise avatar Oct 14 '21 07:10 Kochise