Skip to content
MohistMCPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

i18n

Damn modularity makes ResourceBundle.getBundle not work properly, so make a separate Jar

USE

Gradle

 repositories {
    maven {url "https://maven.mohistmc.com/"}
 }

dependencies {
    implementation 'com.mohistmc:i18n:0.3'
}

Code

// Init
i18n i18n = new i18n(ClassLoader classLoader, Locale locale);
// Use
i18n.get(key);

// Init
i18n i18n = new i18n(Class<?> classz, Locale locale);
// Use
i18n.get(key);

Resource

Create a new default file: \resources\lang\message.properties

More language files: \resources\lang\message_xx_XX.properties

Locale normalisation

Locale.getDefault().toString() is platform dependent and is not guaranteed to be a clean ll_CC value. On macOS it commonly yields zh_CN_#Hans (the script is appended as a locale extension after #) or the BCP-47 style zh-Hans-CN. Feeding those straight into the constructor used to fall back to English, so normalizeLang is provided to canonicalise first:

// "zh_CN_#Hans" -> "zh_CN"   "zh-Hans-CN" -> "zh_CN"
// "zh-Hant-TW"  -> "zh_TW"   "en-us"      -> "en_US"
String lang = i18n.normalizeLang(Locale.getDefault());
i18n i18n = new i18n(ClassLoader classLoader, lang);

normalizeLang accepts a String or a Locale and returns the canonical ll_CC form (lower-case language, upper-case region), falling back to en_US when the input carries no usable language. The constructors parse identifiers through the same logic, so raw macOS values resolve correctly as well.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages