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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.