<?xml version="1.0"?>

<bindings id="stringBundleBindings"
          xmlns="http://www.mozilla.org/xbl"
          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="stringbundle" extends="xul:spring">
    <implementation name="XStringBundle">
      
      <method name="getString">
        <parameter name="aStringKey"/>
        <body>
        <![CDATA[
          try {
            return this._bundle.GetStringFromName(aStringKey);
          }
          catch (e) {
            dump("<StringBundle> Error: Failed to get string from bundle. Are you using the right key?\n");
            dump("The key you provided was: " + aStringKey + "\n");
            dump("The exception thrown was:\n" + e + "\n");
	    return null;
          }
        ]]>
        </body>
      </method>
    
      <property name="stringBundle">
        <getter>
        <![CDATA[
          return this._bundle;
        ]]>
        </getter>
        <setter>
        <![CDATA[
          try {
            var strBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
            strBundleService = strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
            this._bundle = strBundleService.CreateBundle(val, this.appLocale); 
          } 
          catch (ex) {
          }
        ]]>
        </setter>
      </property>

      <property name="appLocale">
        <getter>
        <![CDATA[
          try {
            var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"].getService();
            localeService = localeService.QueryInterface(Components.interfaces.nsILocaleService);
            return localeService.GetApplicationLocale();
          } 
          catch (ex) {
            return null;
          }
        ]]>
        </getter>
      </property>

      <property name="_bundle"/>
    </implementation>
    <handlers>
      <handler event="bindingattached">
      <![CDATA[
        this.stringBundle = this.getAttribute("src");
      ]]>
      </handler>
    </handlers>
  </binding>
  
</bindings>          
