Class Language
- Version:
- 1.0.0
- Author:
- wisdomme
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates a language dictionary by reading a JSON file.Creates a language dictionary from JSON.Creates directly from a dictionary.privateCreates a language whose dictionary is consulted first, falling back tofallbackfor any key this dictionary does not contain. -
Method Summary
Modifier and TypeMethodDescriptionstatic LanguageBuilds aLanguagefrom a YAML language file.getLocalizedText(String str) withFallback(Language fallback) Returns aLanguagethat answers from this dictionary first and, for any key this dictionary lacks, fromfallbackinstead of immediately returning the raw key.
-
Field Details
-
LOGGER
-
GSON
private static final com.google.gson.Gson GSON -
MAP_TYPE
-
dictionary
-
fallback
-
-
Constructor Details
-
Language
Creates a language dictionary by reading a JSON file.- Parameters:
file- the language JSON file
-
Language
Creates directly from a dictionary.- Parameters:
dictionary- the language dictionary
-
Language
Creates a language dictionary from JSON.- Parameters:
json- the JSON string
-
Language
Creates a language whose dictionary is consulted first, falling back tofallbackfor any key this dictionary does not contain.- Parameters:
dictionary- this language's own dictionary, authoritative for every key it containsfallback- consulted only for a key absent fromdictionary; may benull
-
-
Method Details
-
withFallback
Returns aLanguagethat answers from this dictionary first and, for any key this dictionary lacks, fromfallbackinstead of immediately returning the raw key.Real-machine finding (phase 13, PR #418): on an upgraded server a module jar adds a language key, but the copy of that language file already sitting in the module's data folder -- extracted by an older jar -- does not have it. Before this method existed, whichever
Languagethe loader picked (disk, if present at all) was used exclusively, so a key the disk file lacked rendered as its own raw key even though the new jar shipped a translation for it. The disk file stays authoritative for every key it does contain, since server owners customise it.- Parameters:
fallback- the language to consult for a key this dictionary does not contain; may benull, in which case this language is returned unchanged- Returns:
- a language falling back to
fallbackfor missing keys - Throws:
IllegalArgumentException- iffallbackis this language, or iffallback's own fallback chain already contains this language -- either would makegetLocalizedText(java.lang.String)recurse forever for a key present in neither- Since:
- 6.3.0
-
fromYaml
Builds aLanguagefrom a YAML language file.Eight of this ecosystem's sixteen modules ship
lang/*.ymlrather thanlang/*.json, and until 6.3.0 the loader looked only for.jsonand returned an empty dictionary when it found nothing -- silently, so every message in those modules rendered as its own raw key (#389).The YAML is nested and the modules address it with dotted keys (
i18n("world.delete.deleting")), which is exactly the formgetKeys(true)produces, so the flattening is the library's own and not a convention invented here. Section nodes are skipped: only leaves that are actually strings become entries.- Parameters:
reader- the YAML source; the caller owns closing it- Returns:
- a language whose dictionary is the flattened YAML
- Since:
- 6.3.0
-
getLocalizedText
-