MCPcopy Create free account
hub / github.com/BaseXdb/basex / Lang

Class Lang

basex-core/src/main/java/org/basex/core/Lang.java:20–160  ·  view source on GitHub ↗

This class loads language specific texts when the #lang method is called for the first time. @author BaseX Team, BSD License @author Christian Gruen

Source from the content-addressed store, hash-verified

18 * @author Christian Gruen
19 */
20public final class Lang {
21 /** Language suffix. */
22 private static final String SUFFIX = "lang";
23 /** Cached source files. */
24 private static final HashMap<String, String> TEXTS = new HashMap<>();
25 /** Checks which strings have been applied. */
26 private static final HashMap<String, Boolean> CHECK = new HashMap<>();
27
28 /** Private constructor. */
29 private Lang() { }
30
31 /* Reads the language file. */
32 static { read(Prop.language); }
33
34 /**
35 * Reads the specified language file.
36 * @param lang language
37 */
38 private static synchronized void read(final String lang) {
39 TEXTS.clear();
40 CHECK.clear();
41 final String path = SUFFIX + '/' + lang + '.' + SUFFIX;
42 final TokenObjectMap<byte[]> map = Util.properties(path);
43 for(final byte[] key : map) {
44 final String name = Token.string(key), val = Token.string(map.get(key));
45 if(TEXTS.put(name, val.replace("\n", Prop.NL)) != null) {
46 Util.errln("%." + SUFFIX + ": '%' is declared twice", lang, name);
47 }
48 CHECK.put(name, true);
49 }
50 }
51
52 /**
53 * Returns the specified string.
54 * @param key key
55 * @return string
56 */
57 static synchronized String lang(final String key) {
58 if(key == null) {
59 for(final String s : CHECK.keySet()) {
60 Util.errln("%." + SUFFIX + ": '%' can be removed", Prop.language, s);
61 }
62 return "---";
63 }
64
65 final String val = TEXTS.get(key);
66 if(val == null) {
67 Util.errln("%." + SUFFIX + ": '%' is missing", Prop.language, key);
68 return '[' + key + ']';
69 }
70 CHECK.remove(key);
71 return val;
72 }
73
74 /**
75 * Returns the specified string with some text extensions included.
76 * @param key key
77 * @param ext text text extensions

Callers

nothing calls this directly

Calls 1

readMethod · 0.95

Tested by

no test coverage detected