Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/resources/Resources.java @ 3771:04309ca24614
Locales fix
flys-artifacts/trunk@5476 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Christian Lins <christian.lins@intevation.de> |
---|---|
date | Sat, 15 Sep 2012 13:42:44 +0000 |
parents | 7f9fe694f8d1 |
children |
comparison
equal
deleted
inserted
replaced
3770:6a08f4dc790b | 3771:04309ca24614 |
---|---|
83 * @param def A default value that is returned, if <i>key</i> was not found. | 83 * @param def A default value that is returned, if <i>key</i> was not found. |
84 * | 84 * |
85 * @return the translated message. | 85 * @return the translated message. |
86 */ | 86 */ |
87 public static String getMsg(CallMeta meta, String key, String def) { | 87 public static String getMsg(CallMeta meta, String key, String def) { |
88 | |
89 ensureInstance(); | 88 ensureInstance(); |
90 | 89 |
91 Locale[] locales = INSTANCE.getLocales(); | 90 Locale[] locales = INSTANCE.getLocales(); |
92 Locale locale = meta.getPreferredLocale(locales); | 91 Locale locale = meta.getPreferredLocale(locales); |
93 | 92 |
94 return getMsg(locale, key, def); | 93 return getMsg(locale, key, def); |
95 } | 94 } |
96 | 95 |
97 public static String getMsg( | 96 public static String getMsg( |
98 CallMeta meta, | 97 CallMeta meta, |
99 String key, | 98 String key, |
100 Object[] args | 99 Object[] args |
101 ) { | 100 ) { |
102 return getMsg(meta, key, key, args); | 101 return getMsg(meta, key, key, args); |
103 } | 102 } |
104 | 103 |
105 /** | 104 /** |
106 * Returns a translated message based on a template specified by <i>key</i> | 105 * Returns a translated message based on a template specified by <i>key</i> |
112 * @param args The arguments that are necessary for the template. | 111 * @param args The arguments that are necessary for the template. |
113 * | 112 * |
114 * @return a translated string. | 113 * @return a translated string. |
115 */ | 114 */ |
116 public static String getMsg( | 115 public static String getMsg( |
117 CallMeta meta, | 116 CallMeta meta, |
118 String key, | 117 String key, |
119 String def, | 118 String def, |
120 Object[] args) | 119 Object[] args) |
121 { | 120 { |
122 String template = getMsg(meta, key, (String)null); | 121 String template = getMsg(meta, key, (String)null); |
123 | 122 |
124 if (template == null) { | 123 if (template == null) { |
125 return def; | 124 return def; |
126 } | 125 } |
127 | 126 |
128 return MessageFormat.format(template, args); | 127 return format(meta, template, args); |
129 } | 128 } |
130 | 129 |
131 public static String format( | 130 public static String format( |
132 CallMeta meta, | 131 CallMeta meta, |
133 String key, | 132 String key, |
134 String def, | 133 String def, |
135 Object ... args | 134 Object ... args |
136 ) { | 135 ) { |
137 String template = getMsg(meta, key, (String)null); | 136 String template = getMsg(meta, key, (String)null); |
138 | 137 |
139 if (template == null) { | 138 if (template == null) { |
140 template = def; | 139 template = def; |
141 } | 140 } |
142 | 141 |
143 return MessageFormat.format(template, args); | 142 return format(meta, template, args); |
143 } | |
144 | |
145 /** | |
146 * Formats the given template using the arguments with respect of the | |
147 * appropriate locale given by the CallMeta instance. | |
148 */ | |
149 public static String format(CallMeta meta, String templ, Object ... args) { | |
150 Locale locale = getLocale(meta); | |
151 MessageFormat mf = new MessageFormat(templ, locale); | |
152 | |
153 return mf.format(args, new StringBuffer(), null).toString(); | |
144 } | 154 } |
145 | 155 |
146 /** | 156 /** |
147 * This method returns the translated value for <i>key</i> or <i>def</i> if | 157 * This method returns the translated value for <i>key</i> or <i>def</i> if |
148 * <i>key</i> is not existing in the resource bundle. | 158 * <i>key</i> is not existing in the resource bundle. |