1818import java .util .Locale ;
1919import java .util .Map ;
2020import java .util .MissingResourceException ;
21+ import java .util .PropertyResourceBundle ;
2122import java .util .ResourceBundle ;
2223import java .util .concurrent .ConcurrentHashMap ;
2324
4445 */
4546public class LocaleTransposition implements Transposition <String >
4647{
47-
4848 // shared thread safe map between a String(representing the language) and a ResourceBundle.
4949 private static Map <String , ResourceBundle > bundleMap = new ConcurrentHashMap <String , ResourceBundle >();
50-
50+
5151 private final String languageParam ;
5252 private final String bundleName ;
5353
5454 private LocaleTransposition (final String languageParam , final String bundleName )
5555 {
5656 Assert .notNull (languageParam , "Language must not be null." );
5757 Assert .notNull (bundleName , "Bundle must not be null." );
58+
59+ //TODO ensure that we can find a resource bundle with the provided name in the classpath
60+
5861 this .languageParam = languageParam ;
5962 this .bundleName = bundleName ;
6063 }
@@ -107,13 +110,10 @@ public String transpose(Rewrite event, EvaluationContext context, String value)
107110 Locale locale = new Locale (targetLang );
108111 try
109112 {
110- // if no bundle can be found for the targetLang, the system default is used.
111- ResourceBundle loadedBundle = ResourceBundle .getBundle (bundleName , locale );
112-
113- // we only use the bundle if it's what we asked for (avoid using the default locale when not found)
114- if (loadedBundle .getLocale ().getLanguage ().equals (targetLang )){
115- bundleMap .put (targetLang , loadedBundle );
116- }
113+ ResourceBundle loadedBundle = ResourceBundle .getBundle (bundleName , locale ,
114+ ResourceBundle .Control .getNoFallbackControl (ResourceBundle .Control .FORMAT_DEFAULT ));
115+
116+ bundleMap .put (targetLang , loadedBundle );
117117 }
118118 catch (MissingResourceException e )
119119 {
@@ -122,7 +122,8 @@ public String transpose(Rewrite event, EvaluationContext context, String value)
122122 }
123123 }
124124
125- if (bundleMap .containsKey (targetLang )) {
125+ if (bundleMap .containsKey (targetLang ))
126+ {
126127 try
127128 {
128129 // can we received more than one path section? e.g./search/service/
0 commit comments