1 package ca.uhn.fhir.i18n;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.text.MessageFormat;
24 import java.util.Map;
25 import java.util.ResourceBundle;
26 import java.util.concurrent.ConcurrentHashMap;
27
28
29
30
31 public class HapiLocalizer {
32
33 private ResourceBundle myBundle;
34 private final Map<String, MessageFormat> myKeyToMessageFormat = new ConcurrentHashMap<String, MessageFormat>();
35
36 public HapiLocalizer() {
37 myBundle = ResourceBundle.getBundle(HapiLocalizer.class.getPackage().getName() + ".hapi-messages");
38 }
39
40 public String getMessage(String theKey, Object... theParameters) {
41 if (theParameters != null && theParameters.length > 0) {
42 MessageFormat format = myKeyToMessageFormat.get(theKey);
43 if (format != null) {
44 return format.format(theParameters).toString();
45 }
46
47 String formatString = myBundle.getString(theKey);
48 if (formatString== null) {
49 formatString = "!MESSAGE!";
50 }
51
52 format = new MessageFormat(formatString);
53 myKeyToMessageFormat.put(theKey, format);
54 return format.format(theParameters).toString();
55 } else {
56 String retVal = myBundle.getString(theKey);
57 if (retVal == null) {
58 retVal = "!MESSAGE!";
59 }
60 return retVal;
61 }
62 }
63
64
65 }