Javascript String translate()

Description

Javascript String translate()


/**// w  ww.  ja v  a 2 s  .c  o  m
 * (Optional) Extends the class String for i18n
 */
String.prototype.translate = function() {
  return I18N.translateStr(this);
}

Javascript String translate()

/**/*w ww .  j a  v  a 2s.  c  om*/
 * @example
 * translate['Hello world'] = 'Bonjour tout le monde';
 * alert('Hello world'.translate());
 */
var translate = {};
String.prototype.translate = function() {
 return translate[this]?translate[this]:this;
};



PreviousNext

Related