-
Notifications
You must be signed in to change notification settings - Fork 0
Commons Module
H3xadecimal edited this page Mar 9, 2024
·
1 revision
Utilities for language files
This class will load resource from specified ClassLoader as language file
Class cn.afternode.commons.Localizations
Saved in /src/main/resources/lang_en.properties
loc.example=Hello World
loc.placeholder=Hello %name%Localizations loc = new Localizations("lang", Localization.class.getClassLoader(), "en);
System.out.println(loc.get("loc.example"));
Map<String, String> ph = new HashMap<>();
ph.put("name", "AFterNode");
System.out.println(loc.get("loc.placeholder", ph));- prefix Localization file prefix
- loader Class loader for getResourceAsStream
- prefix Localization file prefix
- loader Class loader for getResourceAsStream
- defaultId Localizations will load language file on construct with this id
Load language file from resource with specified ID
<prefix>_<id>.properties will be loaded
Call loadLocalizations(String) with ISO 639 code from Locale.getDefault().getLanguage()
Get locale from loaded file with specified key
If key not present in language file, the key will be returned
Get locale from loaded file with specified key and apply placeholders
e.g. Placeholder in file is %name%, placeholder map is name: XXX