Changeset 135

Show
Ignore:
Timestamp:
02/28/07 17:58:23 (3 years ago)
Author:
tobi
Message:
  • Added private property localeGetter assigned with default method for retrieving the locale
  • Added public setter and getter methods setLocaleGetter and getLocaleGetter for writing and reading localeGetter
  • Replaced occurrences of res.meta.locale with getLocaleGetter()() (fixes #11)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/code/I18n.js

    r110 r135  
    4747    
    4848   /** 
     49    * The default method for retrieving the locale. 
     50    * @ignore 
     51    */ 
     52   var localeGetter = function() { 
     53      return java.util.Locale.getDefault(); 
     54   }; 
     55    
     56   /** 
    4957    * Overwrite the default object containing 
    5058    * the messages (ie. a vanilla EcmaScript object). 
     
    6270   this.getMessages = function() { 
    6371      return messages; 
     72   }; 
     73    
     74   /** 
     75    * Set the method for retrieving the locale. 
     76    * @param {Function} func The getter method 
     77    */ 
     78   this.setLocaleGetter = function(func) { 
     79      if (func && func.constructor == Function) { 
     80         localeGetter = func; 
     81      } else { 
     82         throw Error("Getter method to retrieve locale must be a function"); 
     83      } 
     84      return; 
     85   }; 
     86    
     87   /** 
     88    * Get the method for retrieving the locale. 
     89    * @returns The getter method 
     90    * @type Function 
     91    */ 
     92   this.getLocaleGetter = function() { 
     93      return localeGetter; 
    6494   }; 
    6595    
     
    127157   var translation = null; 
    128158   if (singularKey) { 
    129       // use either the locale defined in res.meta.locale or the jvm default 
    130       var locale = res.meta.locale || java.util.Locale.getDefault(); 
     159      // use the getter method for retrieving the locale 
     160      var locale = this.getLocaleGetter()(); 
    131161      var catalog, key; 
    132162      if ((catalog = jala.i18n.getCatalog(locale))) { 
     
    204234         } 
    205235      } 
    206       // use either the locale defined in res.meta.locale or the jvm default 
    207       var locale = res.meta.locale || java.util.Locale.getDefault(); 
     236      // use the getter method for retrieving the locale 
     237      var locale = this.getLocaleGetter()(); 
    208238      // format the message 
    209239      try {