home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / strres.js < prev    next >
Text File  |  2001-02-14  |  2KB  |  79 lines

  1. var strBundleService = null;
  2. var localeService = null;
  3.  
  4. function srGetAppLocale()
  5. {
  6.   var applicationLocale = null;
  7.  
  8.   if (!localeService) {
  9.       try {
  10.           localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"].getService();
  11.       
  12.           localeService = localeService.QueryInterface(Components.interfaces.nsILocaleService);
  13.       } catch (ex) {
  14.           dump("\n--** localeService failed: " + ex + "\n");
  15.           return null;
  16.       }
  17.   }
  18.   
  19.   applicationLocale = localeService.GetApplicationLocale();
  20.   if (!applicationLocale) {
  21.     dump("\n--** localeService.GetApplicationLocale failed **--\n");
  22.   }
  23.   return applicationLocale;
  24. }
  25.  
  26. function srGetStrBundleWithLocale(path, locale)
  27. {
  28.   var strBundle = null;
  29.  
  30.   if (!strBundleService) {
  31.       try {
  32.           strBundleService =
  33.               Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
  34.           strBundleService = 
  35.               strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  36.       } catch (ex) {
  37.           dump("\n--** strBundleService failed: " + ex + "\n");
  38.           return null;
  39.       }
  40.   }
  41.  
  42.   strBundle = strBundleService.CreateBundle(path, locale); 
  43.   if (!strBundle) {
  44.     dump("\n--** strBundle createInstance failed **--\n");
  45.   }
  46.   return strBundle;
  47. }
  48.  
  49. function srGetStrBundle(path)
  50. {
  51.   var appLocale = srGetAppLocale();
  52.   return srGetStrBundleWithLocale(path, appLocale);
  53. }
  54.  
  55. function selectLocale(event)
  56. {
  57.   try {
  58.     var chromeRegistry = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService();
  59.     if ( chromeRegistry ) {
  60.       chromeRegistry = chromeRegistry.QueryInterface( Components.interfaces.nsIChromeRegistry );
  61.     }
  62.     var node = event.target;
  63.     var langcode = node.getAttribute('data');
  64.     //var old_lang = chromeRegistry.getSelectedLocale("navigator");
  65.     //dump("\n-->old_lang=" + old_lang + "--");
  66.     chromeRegistry.selectLocale(langcode, true);
  67.     dump("\n-->set new lang, langcode=" + langcode + "--");
  68.     var sbundle = srGetStrBundle("chrome://global/locale/brand.properties");
  69.     var alertstr = sbundle.GetStringFromName("langAlert");
  70.     alert(alertstr);
  71.   }
  72.   catch(e) {
  73.     dump("\n--> strres.js: selectLocale() failed!\n");
  74.     return false;
  75.   }
  76.   return true;    
  77. }
  78.  
  79.