Class LanguageBootstrap
java.lang.Object
dev.ua.theroer.magicutils.bootstrap.LanguageBootstrap
Shared language and
Messages wiring for platform bootstrap helpers.
Historically every platform bootstrap (Bukkit, Bungee, Velocity, Fabric,
NeoForge) duplicated the same eight language flags, their setters, and the
apply/close logic. That logic only touches LanguageManager,
Messages, LoggerCore and Platform, all of which are
visible from core, so it lives here as the single source of truth.
Platform builders own an instance and delegate their language setters to it;
command, diagnostics, and messaging wiring stay platform-specific because
those types differ per platform.
Terminology: a scope is the owner name a plugin/mod registers its messages under (plugin name or mod id).
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a language bootstrap with the recommended defaults already applied (every flag on, language"en"). -
Method Summary
Modifier and TypeMethodDescriptionaddMagicUtilsMessages(boolean addMagicUtilsMessages) Toggles adding the bundled MagicUtils default language entries.voidapply(String scope, LanguageManager languageManager, LoggerCore logger) Runs the byte-identical language/messages wiring against a resolved language manager and logger.bindClientLocaleSync(boolean bindClientLocaleSync) Toggles synchronizing a player's language from client locale updates.voidbindClientLocaleSync(MagicRuntime runtime, Platform platform, LanguageManager languageManager) Binds client-locale synchronization on the runtime when enabled.bindLoggerLanguage(boolean bindLoggerLanguage) Toggles binding the language manager to the logger so log output is localized.booleanWhether client-locale synchronization should be bound on the runtime.initLanguage(boolean initLanguage) Toggles automatic language initialization viaLanguageManager.init(String).voidinstallMessagesCloseHooks(MagicRuntime runtime, String scope, LanguageManager languageManager) Installs the messages-related close hooks on the runtime when the corresponding flags are enabled.Sets the default language code to initialize.minimal()Disables all automatic language wiring for callers that manage theLanguageManagerandMessagesthemselves.registerMessages(boolean registerMessages) Toggles registering a scopedMessagesmanager keyed by the plugin name or mod id.booleanWhether a scoped messages registration was requested (drives the close hook that unregisters it).setMessagesManager(boolean setMessagesManager) Toggles setting the globalMessageslanguage manager to this plugin/mod's manager.booleanWhether the global messages manager was set (drives the close hook that clears it).translations(@Nullable Consumer<LanguageManager> translations) Registers plugin/mod translations against the language manager on build.Applies the recommended defaults: every flag enabled.
-
Constructor Details
-
LanguageBootstrap
public LanguageBootstrap()Creates a language bootstrap with the recommended defaults already applied (every flag on, language"en").
-
-
Method Details
-
language
Sets the default language code to initialize. Blank values are ignored.- Parameters:
language- language code (for example,"en")- Returns:
- this
-
initLanguage
Toggles automatic language initialization viaLanguageManager.init(String).- Parameters:
initLanguage- true to initialize the language on build- Returns:
- this
-
bindLoggerLanguage
Toggles binding the language manager to the logger so log output is localized.- Parameters:
bindLoggerLanguage- true to set the logger language manager- Returns:
- this
-
setMessagesManager
Toggles setting the globalMessageslanguage manager to this plugin/mod's manager.- Parameters:
setMessagesManager- true to set the global manager- Returns:
- this
-
registerMessages
Toggles registering a scopedMessagesmanager keyed by the plugin name or mod id.- Parameters:
registerMessages- true to register the scope- Returns:
- this
-
addMagicUtilsMessages
Toggles adding the bundled MagicUtils default language entries.- Parameters:
addMagicUtilsMessages- true to add bundled defaults- Returns:
- this
-
bindClientLocaleSync
Toggles synchronizing a player's language from client locale updates.- Parameters:
bindClientLocaleSync- true to bind client locale synchronization- Returns:
- this
-
translations
Registers plugin/mod translations against the language manager on build.- Parameters:
translations- translation registrar- Returns:
- this
-
withRecommendedDefaults
Applies the recommended defaults: every flag enabled. This is already the initial state, so it exists mainly to make intent explicit and to reset a builder that calledminimal().- Returns:
- this
-
minimal
Disables all automatic language wiring for callers that manage theLanguageManagerandMessagesthemselves. Leaveslanguage(String)untouched.- Returns:
- this
-
bindsClientLocaleSync
public boolean bindsClientLocaleSync()Whether client-locale synchronization should be bound on the runtime.- Returns:
- true when enabled
-
registersMessages
public boolean registersMessages()Whether a scoped messages registration was requested (drives the close hook that unregisters it).- Returns:
- true when enabled
-
setsMessagesManager
public boolean setsMessagesManager()Whether the global messages manager was set (drives the close hook that clears it).- Returns:
- true when enabled
-
apply
Runs the byte-identical language/messages wiring against a resolved language manager and logger. Mirrors the former per-platformprepare()bodies exactly.- Parameters:
scope- owner name (plugin name or mod id) used for the messages scopelanguageManager- resolved language managerlogger- resolved logger core
-
bindClientLocaleSync
public void bindClientLocaleSync(MagicRuntime runtime, Platform platform, LanguageManager languageManager) Binds client-locale synchronization on the runtime when enabled. Mirrors the former per-platformbuildRuntime()block.- Parameters:
runtime- managed runtimeplatform- platform adapterlanguageManager- resolved language manager
-
installMessagesCloseHooks
public void installMessagesCloseHooks(MagicRuntime runtime, String scope, LanguageManager languageManager) Installs the messages-related close hooks on the runtime when the corresponding flags are enabled. Mirrors the former per-platformbuildRuntime()close blocks.- Parameters:
runtime- managed runtimescope- owner name (plugin name or mod id) used for the messages scopelanguageManager- resolved language manager
-