Lang
The lang module manages localisation files, custom messages, and per-player language overrides.
Why a language manager
Hardcoded strings mean one language for everyone and a redeploy for every typo. Rolling your own localisation means a file per language, a lookup with a fallback when a key is missing, argument substitution, and somehow tracking which language each player actually speaks.
MagicUtils lang does that for you: message catalogs per scope, a fallback language, MiniMessage formatting, argument and placeholder substitution, and per-player locale resolution that can follow the player's client language. You reference a key; the right translation for the right audience comes back as an Adventure component.
Before (hardcoded, one language, manual formatting):
After (keyed message, per-player language, MiniMessage):
Setup
Manual setup:
Bootstrap helpers perform the same wiring automatically when language support is enabled.
File Layout And Formats
Language files live under lang/{lang}.{ext} inside the platform config
directory.
- YAML is supported when
magicutils-config-yamlis installed. - JSON / JSONC work out of the box.
- TOML works when
magicutils-config-tomlis installed.
Messages.register(scope, manager) keeps each plugin or mod isolated. Use
Messages.setLanguageManager(...) only when you need the legacy global
fallback.
Resolving Messages
Messages uses MiniMessage for rich output. Positional arguments ({0}, {1},
...) are substituted from the trailing Object... args. When you need to pin a
language explicitly or control escaping, use the query builder (see below).
Query builder
Messages.query(...) (and MessagesView.query(...)) gives fine-grained control
over recipient, language, arguments, and escaping:
Call .escaped() to treat argument values as literal text (MiniMessage tags in
them are not parsed).
Per-Player Languages
setPlayerLanguage(...) accepts UUIDs, Audience, or player objects that
expose getUniqueId(). getMessageFor(audience, key) resolves a message in the
recipient's language.
Following the client locale
Instead of setting each player's language by hand, you can let MagicUtils track the client's own locale. The bootstrap helpers enable this by default; to wire it manually, bind the language manager to the platform:
Each player then sees messages in the language their client reports (falling back to the fallback language when it is not available).
Custom Messages
Custom messages are persisted under the messages section of the active
language file.
Async And Smart Loading
Language loading touches disk. Use the async or smart helpers on blocking-sensitive threads:
Fallbacks And Missing Keys
When the current language is missing a key, MagicUtils falls back to the configured fallback language before logging a missing-message warning.