Class LocaleProvider
java.lang.Object
com.winterhavenmc.library.messagebuilder.resources.configuration.LocaleProvider
- All Implemented Interfaces:
ConfigProvider<LocaleSetting>
A configuration-backed provider for both
Locale
and ZoneId
settings.
This class wraps a LocaleSetting
and provides a centralized access point
for retrieving the user's desired locale and timezone, both of which are commonly
required for time/date formatting and localization operations throughout the plugin.
The LocaleProvider
resolves configuration values from the plugin config.yml
in the following order:
locale
key (preferred)language
key (fallback)Locale.getDefault()
(system fallback)
The timezone
configuration value, if present and valid, is resolved into a
ZoneId
. If the value is invalid or missing, the system default time zone is used.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic LocaleProvider
create
(org.bukkit.plugin.Plugin plugin) Factory method to construct aLocaleProvider
using a plugin's configuration.get()
Returns the resolvedLocaleSetting
based on the plugin configuration.Returns the resolvedLanguageTag
representing the locale tag.Returns theLocale
object derived from the configuration.Returns the configuredZoneId
if valid, or the system default otherwise.
-
Method Details
-
create
Factory method to construct aLocaleProvider
using a plugin's configuration.This method attempts to extract valid configuration values in the following order:
locale
setting (must be a valid BCP-47 language tag)language
setting (fallback, same format or else ignored)- System default locale and timezone as final fallback
- Parameters:
plugin
- the plugin whose configuration will be consulted- Returns:
- a new
LocaleProvider
with dynamic access to locale and time zone settings
-
get
Returns the resolvedLocaleSetting
based on the plugin configuration.- Specified by:
get
in interfaceConfigProvider<LocaleSetting>
- Returns:
- a locale setting encapsulating a
LanguageTag
-
getLanguageTag
Returns the resolvedLanguageTag
representing the locale tag.- Returns:
- a valid LanguageTag
-
getLocale
Returns theLocale
object derived from the configuration.- Returns:
- a Java
Locale
-
getZoneId
Returns the configuredZoneId
if valid, or the system default otherwise.- Returns:
- the applicable time zone as represented by a
ZoneId
object.
-