applocales
Provide conversion services between python.locale and host languages.
Attributes
DEFAULT_LANG_DIR = 'LTR'
module-attribute
DEFAULT_LOCALE = AppLocale(lang_type=ApplicationServices.LanguageType.English_USA, lang_name='English USA', locale_codes=['en_us', 'english'])
module-attribute
APP_LOCALES = [DEFAULT_LOCALE, AppLocale(lang_type=ApplicationServices.LanguageType.German, lang_name='Deutsch', locale_codes=['de_de', 'german']), AppLocale(lang_type=ApplicationServices.LanguageType.Spanish, lang_name='español', locale_codes=['es_es', 'spanish']), AppLocale(lang_type=ApplicationServices.LanguageType.French, lang_name='français', locale_codes=['fr_fr', 'french']), AppLocale(lang_type=ApplicationServices.LanguageType.Italian, lang_name='italiano', locale_codes=['it_it', 'italian']), AppLocale(lang_type=ApplicationServices.LanguageType.Dutch, lang_name='Nederlands', locale_codes=['nl_nl', 'nl_be', 'dutch']), AppLocale(lang_type=ApplicationServices.LanguageType.Chinese_Simplified, lang_name='简体中文', locale_codes=['chinese_s', 'chinese']), AppLocale(lang_type=ApplicationServices.LanguageType.Chinese_Traditional, lang_name='繁體中文', locale_codes=['chinese_t', 'chinese']), AppLocale(lang_type=ApplicationServices.LanguageType.Japanese, lang_name='日本語', locale_codes=['ja', 'japanese']), AppLocale(lang_type=ApplicationServices.LanguageType.Korean, lang_name='한국어', locale_codes=['ko', 'korean']), AppLocale(lang_type=ApplicationServices.LanguageType.Russian, lang_name='Русский', locale_codes=['ru', 'russian']), AppLocale(lang_type=ApplicationServices.LanguageType.Czech, lang_name='Čeština', locale_codes=['cs', 'czech']), AppLocale(lang_type=ApplicationServices.LanguageType.Polish, lang_name='Polski', locale_codes=['pl', 'polish']), AppLocale(lang_type=ApplicationServices.LanguageType.Hungarian, lang_name='Magyar', locale_codes=['hu', 'hungarian']), AppLocale(lang_type=ApplicationServices.LanguageType.Brazilian_Portuguese, lang_name='Português do Brasil', locale_codes=['pt_br', 'portuguese_brazil', 'brazilian', 'portuguese', 'pt_pt'])]
module-attribute
Classes
AppLocale(lang_type, locale_codes, lang_name=None, lang_dir=DEFAULT_LANG_DIR)
Bases: object
Type representing a language option.
Source code in pyrevitlib/pyrevit/coreutils/applocales.py
Attributes
lang_type = lang_type
instance-attribute
lang_name = lang_name
instance-attribute
lang_dir = lang_dir
instance-attribute
locale_codes = locale_codes
instance-attribute
locale_code = self.locale_codes[0]
instance-attribute
Functions
get_applocale_by_local_code(locale_code)
Return application locale by locale code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
locale_code |
str
|
locale code |
required |
Returns:
Type | Description |
---|---|
AppLocale
|
application locale |
Source code in pyrevitlib/pyrevit/coreutils/applocales.py
get_applocale_by_lang_type(lang_type)
Return application locale by language type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lang_type |
LanguageType | str
|
language type |
required |
Returns:
Type | Description |
---|---|
AppLocale
|
application locale |
Source code in pyrevitlib/pyrevit/coreutils/applocales.py
get_applocale_by_lang_name(lang_name)
Return application locale by language name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lang_name |
str
|
language name |
required |
Returns:
Type | Description |
---|---|
AppLocale
|
application locale |
Source code in pyrevitlib/pyrevit/coreutils/applocales.py
get_current_applocale()
Return the current locale.
This is the user locale, if set, or the host application locale otherwise.
Returns:
Type | Description |
---|---|
AppLocale
|
current locale |
Source code in pyrevitlib/pyrevit/coreutils/applocales.py
get_host_applocale()
get_locale_string(string_dict)
Returns the correct string from given dict based on host language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string_dict |
dict[str, str]
|
dict of strings in various locales |
required |
Returns:
Type | Description |
---|---|
str
|
string in correct locale |
Examples:
data = {"en_us":"Hello", "chinese_s":"你好"}
from pyrevit.coreutils import applocales
# assuming running Revit is Chinese
applocales.get_locale_string(data)