1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.util; |
22 |
|
|
23 |
|
import java.text.MessageFormat; |
24 |
|
import java.util.HashSet; |
25 |
|
import java.util.Locale; |
26 |
|
import java.util.ResourceBundle; |
27 |
|
import java.util.ResourceBundle.Control; |
28 |
|
import java.util.Set; |
29 |
|
|
30 |
|
import jalview.bin.Console; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
@author |
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 13 |
Complexity Density: 0.39 |
|
39 |
|
public class MessageManager |
40 |
|
{ |
41 |
|
private static ResourceBundle rb; |
42 |
|
|
43 |
|
private static Locale loc; |
44 |
|
|
45 |
|
private static Set<String> reportedMissing = new HashSet<>(); |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
47 |
0 |
static... |
48 |
|
{ |
49 |
0 |
try |
50 |
|
{ |
51 |
|
|
52 |
0 |
loc = Locale.getDefault(); |
53 |
|
|
54 |
|
|
55 |
0 |
Console.info("Getting messages for lang: " + loc); |
56 |
0 |
Control control = Control.getControl(Control.FORMAT_PROPERTIES); |
57 |
0 |
rb = ResourceBundle.getBundle("lang.Messages", loc, control); |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
} catch (Exception q) |
64 |
|
{ |
65 |
0 |
Console.warn("Exception when initting Locale for i18n messages\n" |
66 |
|
+ q.getMessage()); |
67 |
0 |
q.printStackTrace(); |
68 |
|
} catch (Error v) |
69 |
|
{ |
70 |
0 |
Console.warn("Error when initting Locale for i18n messages\n" |
71 |
|
+ v.getMessage()); |
72 |
0 |
v.printStackTrace(); |
73 |
|
} |
74 |
|
|
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
@return |
83 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
84 |
0 |
public static String getString(String key)... |
85 |
|
{ |
86 |
0 |
String value = "[missing key] " + key; |
87 |
0 |
try |
88 |
|
{ |
89 |
0 |
value = rb.getString(key); |
90 |
|
} catch (Exception e) |
91 |
|
{ |
92 |
0 |
String msg = "I18N missing: " + loc + "\t" + key; |
93 |
0 |
logWarning(key, msg); |
94 |
|
} |
95 |
0 |
return value; |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
public static Locale getLocale()... |
99 |
|
{ |
100 |
0 |
return loc; |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
|
110 |
|
@return |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
112 |
0 |
public static String formatMessage(String key, Object... params)... |
113 |
|
{ |
114 |
0 |
try |
115 |
|
{ |
116 |
0 |
return MessageFormat.format(rb.getString(key), params); |
117 |
|
} catch (Exception e) |
118 |
|
{ |
119 |
0 |
Console.warn("I18N missing: " + loc + "\t" + key); |
120 |
|
} |
121 |
0 |
String value = "[missing key] " + key + ""; |
122 |
0 |
for (Object p : params) |
123 |
|
{ |
124 |
0 |
value += " '" + p.toString() + "'"; |
125 |
|
} |
126 |
0 |
return value; |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
@param |
135 |
|
|
136 |
|
@return |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
public static String formatMessage(String key, String[] params)... |
139 |
|
{ |
140 |
0 |
return formatMessage(key, (Object[]) params); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
@param |
157 |
|
@return |
158 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
159 |
0 |
public static String getStringOrReturn(String keyroot, String name)... |
160 |
|
{ |
161 |
0 |
String smkey = keyroot |
162 |
|
+ name.toLowerCase(Locale.ROOT).replaceAll(" ", ""); |
163 |
0 |
try |
164 |
|
{ |
165 |
0 |
name = rb.getString(smkey); |
166 |
|
} catch (Exception x) |
167 |
|
{ |
168 |
0 |
String msg = "I18N missing key with root " + keyroot + ": " + loc |
169 |
|
+ "\t" + smkey; |
170 |
0 |
logWarning(smkey, msg); |
171 |
|
} |
172 |
0 |
return name; |
173 |
|
} |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
@param |
179 |
|
@param |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
181 |
0 |
private static void logWarning(String key, String msg)... |
182 |
|
{ |
183 |
0 |
if (!reportedMissing.contains(key)) |
184 |
|
{ |
185 |
0 |
reportedMissing.add(key); |
186 |
0 |
Console.info(msg); |
187 |
|
} |
188 |
|
} |
189 |
|
} |