- Timestamp:
- 2022-09-08T11:08:46+12:00 (20 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/Dictionary.java
r36108 r36592 32 32 /** The default servlet dictionary */ 33 33 public static final String core_servlet_dictionary_name = "core_servlet_dictionary"; 34 34 /** Fallback language */ 35 protected static final String fallback_language = "en"; 36 /** THe string to mark a value as awaiting translator input */ 37 public static final String PENDING_STR = "[PENDING]"; 35 38 /** The locale of this dictionary. */ 36 39 protected Locale locale = null; … … 39 42 protected String resource = null; 40 43 41 /**44 /** 42 45 * The ResourceBundle which contains the raw key-value mappings. Loaded from 43 46 * a file named "resource_locale.properties … … 225 228 // with the resource as UTF-8, and so not conversion is needed 226 229 String initial = this.raw.getString(key); 227 228 230 // if we haven't been given any args, don't bother looking for them 229 231 if (args == null) … … 244 246 public static String getTextString(String key, String lang, String[] args, String dictionary_name, Class class_obj, String stop_at_class, ClassLoader class_loader) 245 247 { 246 247 248 if (dictionary_name == null && class_obj == null) { 248 249 // no dictionary or class was specified, just use the default … … 253 254 if (dictionary_name != null) 254 255 { 255 // just try the one specified dictionary 256 Dictionary dict = new Dictionary(dictionary_name, lang, class_loader); 257 String result = dict.get(key, args); 258 if (result == null) 259 { // not found 260 261 //logger.debug("couldn't find key in dict, "+dictionary_name+" "+key); 262 //return "_" + key + "_"; // should we use this?? 263 return null; 264 } 265 return result; 256 // just try the one specified dictionary 257 return createDictionaryAndGetString(dictionary_name, class_loader, key, lang, args); 266 258 } 267 259 … … 269 261 String original_class_name = class_obj.getName(); 270 262 original_class_name = original_class_name.substring(original_class_name.lastIndexOf('.') + 1); 271 Dictionary dict = new Dictionary(original_class_name, lang, class_loader); 272 String result = dict.get(key, args); 263 String result = createDictionaryAndGetString(original_class_name, class_loader, key, lang, args); 273 264 if (result != null) 274 265 { … … 288 279 break; 289 280 } 290 dict = new Dictionary(class_name, lang, class_loader); 291 result = dict.get(key, args); 281 result = createDictionaryAndGetString(class_name, class_loader, key, lang, args); 292 282 if (result != null) { 293 283 return result; … … 297 287 298 288 // if we got here, class names were no help, try the default dictionary 299 dict = new Dictionary(core_servlet_dictionary_name, lang, class_loader);300 289 301 290 // First we try the key qualified with the original class name … … 303 292 // default properties file) 304 293 String full_key = original_class_name+"."+key; 305 result = dict.get(full_key, args);294 result = createDictionaryAndGetString(core_servlet_dictionary_name, class_loader, full_key, lang, args); 306 295 if (result == null) { 307 result = dict.get(key, args); 296 // try the key by itself without class qualified prefix 297 result = createDictionaryAndGetString(core_servlet_dictionary_name, class_loader, key, lang, args); 308 298 } 309 299 return result; … … 311 301 } 312 302 303 public static String createDictionaryAndGetString(String dictionary_name, ClassLoader class_loader, String key, String lang, String[] args) { 304 Dictionary dict = new Dictionary(dictionary_name, lang, class_loader); 305 String result = dict.get(key, args); 306 // if we have a pending flag, then try the base language 307 if (result != null && result.startsWith(PENDING_STR) && !lang.equals(fallback_language)) { 308 dict = new Dictionary(dictionary_name, fallback_language, class_loader); 309 result = dict.get(key, args); 310 } 311 return result; 312 } 313 314 315 313 316 }
Note:
See TracChangeset
for help on using the changeset viewer.