Core - Translator Module
anvil.lib.translator
LANGUAGES = ('en_US', 'en_GB', 'de_DE', 'es_ES', 'es_MX', 'fr_FR', 'fr_CA', 'it_IT', 'pt_BR', 'pt_PT', 'ru_RU', 'zh_CN', 'zh_TW', 'nl_NL', 'bg_BG', 'cs_CZ', 'da_DK', 'el_GR', 'fi_FI', 'hu_HU', 'id_ID', 'nb_NO', 'pl_PL', 'sk_SK', 'sv_SE', 'tr_TR', 'uk_UA')
module-attribute
The languages Minecraft can show, in the order their .lang files are listed.
AnvilTranslator
__export__()
Export translations to Anvil's .lang file format.
__init__()
Collect localization entries during compilation, merge them with localization.csv, optionally fill missing translations, and export Minecraft .lang files.
add_entries(entries)
Add multiple localization entries.
add_localization_entry(key, value)
Add or update a localization entry in the source language.
auto_translate_all(languages=None)
Queue languages for translation during the next export sync.
format_key(key)
Format a localization key using only alphanumeric characters and dots, no starting with a digit, suitable for use in Minecraft .lang files.
get_localization_value(key)
Return the current source-language value for a localization key.
localize(text, prefix, suffix=None)
Adds text under a key made from it, and returns the key.
The key is <prefix>.<safe_key(text)>, followed by .<suffix> when given.
Example
AnvilTranslator().localize("Read Book", prefix="action.interact") 'action.interact.read_book'
safe_key(text)
staticmethod
Display text as a safe snake_case key segment.
Accents are dropped, \n line breaks count as spaces, and every run of characters
other than lowercase letters and digits becomes one _. A segment that would start
with a digit gets a leading _.
Example
AnvilTranslator.safe_key("Captain's Log\nDay 1") 'captain_s_log_day_1'