I18n

From PlainOldWebserver

Jump to: navigation, search

Firefox has some very useful tools for internationalization. If you can master these tools, you will be among the few. Most software projects seem to think of internationalization after the software has been written. Then, it is too late. The code here finds the boundaries between words or, in chinese, characters.


 <?sjs
   try {
     var scanner = Components.classes["@mozilla.org/intl/semanticunitscanner;1"]
         .createInstance(Components.interfaces.nsISemanticUnitScanner);
     var text = decodeURI("%E6%9C%88%E6%9C%88");
     // var text = "An apple a day";
     scanner.start(null);
     var begin = new Object();
     var end = new Object();
     var next_available = scanner.next(text, text.length, 0, false, begin, end);
     var sub = text.substring(0,end.value);
     alert("first word is "+sub);
   } catch(e) {
     alert(e);
   }
 ?>

Result:

 (alert) first word is 月
Personal tools
Navigation