Loading ...
Sorry, an error occurred while loading the content.

Quick-n-Dirty Key-Value Pair Text Storage

Expand Messages
  • Hollywood
    As all the language strings for my application are stored in a gettext based system on the server, I needed some way to utilize strings in some of my YUI
    Message 1 of 1 , Dec 29, 2007
    • 0 Attachment
      As all the language strings for my application are stored in a gettext based system on the server, I needed some way to utilize strings in some of my YUI functionality (such as my validation form class I'm working on and some expanded dialogs).  So here is a quick-n-dirty key-value pair extension to the YAHOO.lang class... its really quite brain dead, probably replace it at some time, but it works so...
       
      /* ********************************************************************
       * YAHOO.Lang Translation Extension
       *
       *  LICENSE
       *
       * Code licensed under the BSD License:
       * http://developer.yahoo.net/yui/license.txt
       * ********************************************************************/
       
      /**
       * Provides the a quick-n-dirty global text storage (key-value pair)
       * extension to the YAHOO.lang.
       */
       
      /**
      * Gets a text value based on the given key.  Returns an empty string
      * if the key is not found or there are no stored text values.
      * @method isDirty
      * @param {String} key The key used to retrieve the text value.
      */
      YAHOO.lang.getText = function(key)
      {
          if (!YAHOO.lang._text)
              return "";
             
          var text = YAHOO.lang._text[key];
          if (!text)
              text = "";
             
          return text;
      }
       
      /**
      * Set a text value for a given key.
      * @method isDirty
      * @param {String} key The key used to retrieve the text value.
      * @param {String} value The text value to be paired with the key.
      */
      YAHOO.lang.setText = function(key, value)
      {
          if (!YAHOO.lang._text)
              YAHOO.lang._text = [];
             
          YAHOO.lang._text[key] = value;
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.