JavaScript i18n String object & localize method


/ Published in: JavaScript
Save to your folder(s)

This snippet extends the String object so that you can localize() i18n strings


Copy this code and paste it in your HTML
  1. String.prototype.localize = function(){
  2. var cReturnValue = (i18n) ? i18n[this] : this;
  3.  
  4. if(!cReturnValue){
  5. cReturnValue = "§§§" + this + "§§§";
  6. } else {
  7. for (var i = 0; i < arguments.length; i++){
  8. cReturnValue = cReturnValue.replace("{" + i + "}", arguments[i]);
  9. }
  10. }
  11. return cReturnValue;
  12. };

URL: http://kaedatorum.net/blog

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.