Localization
There are two ways of localizing your code. First, the Translator and a simple language switch. Whichever option you choose, the localization happens on start up. If you change the language, the program has to be restarted.
formify.localization
Translator
By the default, the system language is used (i.e. "en", "de", "fr", ...)
language = language
instance-attribute
Set the current language (usually a language code)
add(id, **langauges)
__call__(id)
load(file_name)
Reads all translations into a JSON file.
save(file_name)
Dumps all translations into a JSON file.
default_translator(*args, **kwargs)
Returns a Translator
, populated with translations for default menu items (Open, Close, ...) for german and english.
args and kwargs are passed to the Translator(args, **kwargs).
make_language_switch(translator, language_order)
Makes a function, that selects the argument corresponding to the current language. Best read the example below:
translator = Translator()
switch = make_language_switch(translator, ["en", "de"])
translator.language = "en"
print(switch("open", "öffnen")) # prints "open"
translator.language = "de"
print(switch("open", "öffnen")) # prints "öffnen"
# set the text of a button
ControlButton(switch("open", "öffnen"))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
translator |
Translator
|
used to determine the current language |
required |
language_order |
list
|
language order of the language switch arguments |
required |
Returns:
Name | Type | Description |
---|---|---|
language_switch |
callable
|
language switch function |