Changeset 36592 for main/trunk
- Timestamp:
- 2022-09-08T11:08:46+12:00 (20 months ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ServiceRack.java
r33774 r36592 575 575 * getTextString - retrieves a language specific text string for the given 576 576 * key and locale, from the specified resource_bundle (dictionary) 577 * dictionary may be null, in which case it will use class names 577 578 */ 578 579 protected String getTextString(String key, String lang, String dictionary, String[] args) … … 584 585 protected String getMetadataNameText(String key, String lang) 585 586 { 586 587 String properties_name = "metadata_names"; 588 Dictionary dict = new Dictionary(properties_name, lang); 589 590 String result = dict.get(key); 591 if (result == null) 592 { // not found 593 return null; 594 } 595 return result; 587 return Dictionary.getTextString(key, lang, null, "metadata_names", null, null, this.class_loader); 596 588 } 597 589 } -
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 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DisplayItemUtil.java
r36507 r36592 85 85 if (best_di != null) { 86 86 // look up the dictionary 87 String value = getTextString(best_di.getAttribute(GSXML.KEY_ATT), lang, best_di.getAttribute(GSXML.DICTIONARY_ATT), class_loader);87 String value = Dictionary.createDictionaryAndGetString(best_di.getAttribute(GSXML.DICTIONARY_ATT), class_loader, best_di.getAttribute(GSXML.KEY_ATT), lang, null); 88 88 if (value != null) { 89 89 // copy the node now. Don't want to be modifying the underlying list as can lead to concurrent access problems. … … 127 127 } 128 128 129 protected static String getTextString(String key, String lang, String dictionary, ClassLoader class_loader) {130 return getTextString(key, lang, dictionary, null, class_loader);131 }132 133 protected static String getTextString(String key, String lang, String dictionary, String[] args, ClassLoader class_loader)134 {135 Dictionary dict;136 if (class_loader != null) {137 dict = new Dictionary(dictionary, lang, class_loader);138 } else {139 dict = new Dictionary(dictionary, lang);140 }141 String result = dict.get(key, args);142 return result;143 }144 145 129 146 130 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java
r26196 r36592 113 113 // if (m.text == null || new_lang) 114 114 // { 115 Dictionary dict = new Dictionary(m.bundle, lang, this.class_loader); 116 m.text = dict.get(m.key, null); 115 m.text = Dictionary.createDictionaryAndGetString(m.bundle, this.class_loader, m.key, lang, null); 117 116 // } 118 117 // we assume that dictionary entries will contain no macros -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java
r36508 r36592 257 257 258 258 // try the specified dictionary first 259 Dictionary dict = new Dictionary(dictionary_name, lang, my_loader); 260 String result = dict.get(key, args); 259 String result = Dictionary.createDictionaryAndGetString(dictionary_name, my_loader, key, lang, args); 261 260 if (result == null) { 262 261 // fall back to a general interface text search … … 300 299 // now we allow looking for files in the interface's resources folder 301 300 CustomClassLoader my_loader = new CustomClassLoader(XSLTUtil.class.getClassLoader(), GSFile.interfaceResourceDir(GlobalProperties.getGSDL3Home(), interface_name)); 302 Dictionary dict = new Dictionary("interface_" + interface_name, lang, my_loader); 303 304 String result = dict.get(key, args); 301 String result = Dictionary.createDictionaryAndGetString("interface_"+interface_name, my_loader, key, lang, args); 305 302 if (result == null) 306 303 { 307 304 //if not found, search a separate subdirectory named by the interface name. this is used for eg the flax interface. this could be replaced by new class loader option? 308 305 String sep_interface_dir = interface_name + File.separatorChar + lang + File.separatorChar + "interface"; 309 dict = new Dictionary(sep_interface_dir, lang); 310 result = dict.get(key, args); 306 result = Dictionary.createDictionaryAndGetString(sep_interface_dir, my_loader, key, lang, args); 311 307 if (result != null) 312 308 { … … 317 313 if (result == null && !interface_name.startsWith("default")) { 318 314 // not found, try the default interface 315 String dictionary_name; 319 316 if (interface_name.endsWith("2")) { // hack for interface_xxx2.properties 320 dict = new Dictionary("interface_default2", lang);317 dictionary_name = "interface_default2"; 321 318 } else { 322 dict = new Dictionary("interface_default", lang); 323 319 dictionary_name = "interface_default"; 324 320 } 325 result = dict.get(key, args);321 result = Dictionary.createDictionaryAndGetString(dictionary_name, my_loader, key, lang, args); 326 322 } 327 323 … … 409 405 410 406 CustomClassLoader class_loader = new CustomClassLoader(XSLTUtil.class.getClassLoader(), GSFile.collectionResourceDir(GSFile.siteHome(GlobalProperties.getGSDL3Home(), site_name), collection)); 411 Dictionary dict = new Dictionary("interface_custom", lang, class_loader); 412 String result = dict.get(key, args); 407 String result = Dictionary.createDictionaryAndGetString("interface_custom", class_loader, key, lang, args); 413 408 if (result != null) 414 409 { … … 437 432 public static String getGenericTextWithArgs(String dictionary_name, String lang, String key, String[] args) 438 433 { 439 Dictionary dict = new Dictionary(dictionary_name, lang); 440 String result = dict.get(key, args); 434 String result = Dictionary.createDictionaryAndGetString(dictionary_name, null, key, lang, args); 441 435 if (result == null) { 442 436 return "_"+dictionary_name+"_"+key+"_";
Note:
See TracChangeset
for help on using the changeset viewer.