LanguageManager Internationalization
Estimated reading time: 3 minutesOverview
LanguageManager is the framework’s internationalization/localization system. It provides translation support for mod authors, with multi-language switching, automatic translation lookup, and efficient queries.
LanguageManager is accessible via maplebirch.lang. Translation keys and the Language property are also exposed on maplebirch for convenience.
Core API
t(key, space?)
Get the translated text for a key in the current language.
- @param
key(string): Translation key. - @param
space(boolean): Iftrueand the current language is EN, append a space to the result. Defaultfalse. - @return (string): Translation for the current language, or
[key]if the key is not found.
auto(text)
Auto-detect the given text and return its translation in the current language.
- @param
text(string): Source text to translate. - @return (string): Translation in the current language, or the original text if no translation exists.
Language property
Get or set the current system language. Setting the language triggers the :language event and clears the cache.
Configuration
Language files are configured through AddonPlugin. Set params.language in your mod’s addonPlugin entry in boot.json. Three modes are supported:
Mode 1: Auto-import all languages
Scans and imports all supported language files from the mod’s translations/ directory.
- Value:
true - Supported formats:
{language_code}.json,{language_code}.yml,{language_code}.yaml(e.g.en,cn,ja, case-insensitive) - Priority:
json > yml > yamlfor the same language code
Directory structure example:
Mode 2: Import specified languages
Imports only the listed languages; files are looked up in that order.
- Value: Array of language codes, e.g.
["EN", "CN", "JA"] - Each language tries:
json,yml,yamlin turn - Skips a language and logs a warning if its file is not found
Mode 3: Custom file paths
Define explicit paths per language.
- Value: Object with language codes as keys and
{ "file": "path" }as values
Directory structure example:
