Changeset 36592 for main/trunk


Ignore:
Timestamp:
2022-09-08T11:08:46+12:00 (20 months ago)
Author:
kjdon
Message:

modified Dictionary, so that if a lang fragment starts with [PENDING], then don't use it. This is to allow the addition of old strings which will help the translators, but which are too out of date to display in the interface. OTher classes use of Dictionary modified so that they go through getTextString, or createDictionaryAndGetString, thereby benifitting from the pending stuff

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  
    575575     * getTextString - retrieves a language specific text string for the given
    576576     * key and locale, from the specified resource_bundle (dictionary)
     577         * dictionary may be null, in which case it will use class names
    577578     */
    578579    protected String getTextString(String key, String lang, String dictionary, String[] args)
     
    584585    protected String getMetadataNameText(String key, String lang)
    585586    {
    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);
    596588    }
    597589}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/Dictionary.java

    r36108 r36592  
    3232    /** The default servlet dictionary */
    3333    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]";
    3538    /** The locale of this dictionary. */
    3639    protected Locale locale = null;
     
    3942    protected String resource = null;
    4043
    41     /**
     44    /**
    4245     * The ResourceBundle which contains the raw key-value mappings. Loaded from
    4346     * a file named "resource_locale.properties
     
    225228            // with the resource as UTF-8, and so not conversion is needed
    226229            String initial = this.raw.getString(key);
    227 
    228230            // if we haven't been given any args, don't bother looking for them
    229231            if (args == null)
     
    244246    public static String getTextString(String key, String lang, String[] args, String dictionary_name, Class class_obj, String stop_at_class, ClassLoader class_loader)
    245247  {
    246 
    247248      if (dictionary_name == null && class_obj == null) {
    248249      // no dictionary or class was specified, just use the default
     
    253254      if (dictionary_name != null)
    254255      {
    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);
    266258      }
    267259
     
    269261      String original_class_name = class_obj.getName();
    270262      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);
    273264      if (result != null)
    274265      {
     
    288279          break;
    289280      }
    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);
    292282      if (result != null) {
    293283          return result;
     
    297287
    298288      // if we got here, class names were no help, try the default dictionary
    299       dict = new Dictionary(core_servlet_dictionary_name, lang, class_loader);
    300289
    301290      // First we try the key qualified with the original class name
     
    303292      // default properties file)
    304293      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);
    306295      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);
    308298      }
    309299      return result;
     
    311301  }
    312302
     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 
    313316}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DisplayItemUtil.java

    r36507 r36592  
    8585    if (best_di != null) {
    8686        // 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);
    8888        if (value != null) {
    8989        // copy the node now. Don't want to be modifying the underlying list as can lead to concurrent access problems.
     
    127127  }
    128128
    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  
    145129
    146130}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GS2MacroResolver.java

    r26196 r36592  
    113113              // if (m.text == null || new_lang)
    114114              // {
    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);
    117116                    //  }
    118117                // we assume that dictionary entries will contain no macros
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/XSLTUtil.java

    r36508 r36592  
    257257
    258258        // 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);
    261260        if (result == null) {
    262261          // fall back to a general interface text search
     
    300299    // now we allow looking for files in the interface's resources folder
    301300    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);
    305302    if (result == null)
    306303      { 
    307304    //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?
    308305    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);
    311307    if (result != null)
    312308      {
     
    317313    if (result == null && !interface_name.startsWith("default")) {
    318314      // not found, try the default interface
     315      String dictionary_name;
    319316      if (interface_name.endsWith("2")) { // hack for interface_xxx2.properties
    320     dict = new Dictionary("interface_default2", lang);
     317    dictionary_name = "interface_default2";
    321318      } else {
    322     dict = new Dictionary("interface_default", lang);
    323    
     319    dictionary_name = "interface_default";
    324320      }
    325       result = dict.get(key, args);
     321      result = Dictionary.createDictionaryAndGetString(dictionary_name, my_loader, key, lang, args);
    326322    }
    327323       
     
    409405
    410406            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);
    413408            if (result != null)
    414409            {
     
    437432  public static String getGenericTextWithArgs(String dictionary_name, String lang, String key, String[] args)
    438433  {
    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);
    441435    if (result == null) {
    442436      return "_"+dictionary_name+"_"+key+"_";
Note: See TracChangeset for help on using the changeset viewer.