      1 ﻿
      2 /**
      3  * @name	CeL function for locale
      4  * @fileoverview
      5  * 本檔案包含了 locale 的 functions。
      6  * @since
      7  */
      8
      9 /*
     10 http://blog.miniasp.com/post/2010/12/24/Search-and-Download-International-Terminology-Microsoft-Language-Portal.aspx
     11 http://www.microsoft.com/language/zh-tw/default.aspx
     12 Microsoft | 語言入口網站
     13 */
     14
     15 if (typeof CeL === 'function'){
     16
     17 /**
     18  * 本 module 之 name(id)，<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。
     19  * @type	String
     20  * @constant
     21  * @inner
     22  * @ignore
     23  */
     24 var module_name = 'locale';
     25
     26 //===================================================
     27 /**
     28  * 若欲 include 整個 module 時，需囊括之 code。
     29  * @type	Function
     30  * @param	{Function} library_namespace	namespace of library
     31  * @param	load_arguments	呼叫時之 argument(s)
     32  * @return
     33  * @name	CeL.locale
     34  * @constant
     35  * @inner
     36  * @ignore
     37  */
     38 var code_for_including = function(library_namespace, load_arguments) {
     39
     40
     41 /**
     42  * null module constructor
     43  * @class	locale 的 functions
     44  */
     45 CeL.locale
     46 = function() {
     47 	//	null module constructor
     48 };
     49
     50 /**
     51  * for JSDT: 有 prototype 才會將之當作 Class
     52  */
     53 CeL.locale
     54 .prototype = {
     55 };
     56
     57
     58
     59
     60
     61 //	i18n系列	==================
     62
     63 /*	setup message of various languages for i18n (internationalization)
     64 var languagesMessage={},defaultLanguage,useLanguage,languageAlias;
     65 setObjValue('languageAlias','en_US=en_US,en=en_US,English=en_US,zh_TW=zh_TW,zh=zh_TW,tw=zh_TW,中文=zh_TW,Chinese=zh_TW,日本語=ja_JP,Japanese=ja_JP,ja_JP=ja_JP,ja=ja_JP,jp=ja_JP');
     66 */
     67 //getLanguageAlias[generateCode.dLK]='languageAlias,existLanguageAlias';
     68 function getLanguageAlias(language){
     69  if(existLanguageAlias(language))language=languageAlias[language];
     70  return language;
     71 }
     72
     73 //existLanguageAlias[generateCode.dLK]='languageAlias';
     74 function existLanguageAlias(language){
     75  return language in languageAlias;
     76 }
     77
     78 //	(language, if you want to setup defaultLanguage as well)
     79 //setLanguage[generateCode.dLK]='getLanguageAlias,defaultLanguage,useLanguage';
     80 function setLanguage(language,mode){
     81  language=getLanguageAlias(language);
     82  if(mode)defaultLanguage=language;
     83  else useLanguage=language;
     84  return useLanguage;
     85 }
     86
     87 //	setMessage(messageIndex1,[local,message],[local,message],messageIndex2,[local,message],[local,message],..)
     88 //setMessage[generateCode.dLK]='languagesMessage,defaultLanguage,getLanguageAlias';
     89 function setMessage(){
     90  //if(!defaultLanguage)defaultLanguage='en_US';
     91  //	n.preference('intl.charset.default')	http://chaichan.hp.infoseek.co.jp/qa3500/qa3803.htm	http://articles.techrepublic.com.com/5100-22-5069931.html
     92  //	http://forum.mozilla.gr.jp/?mode=al2&namber=5608&rev=&&KLOG=39
     93  //	navigator.language=general.useragent.locale @ about:config
     94  //	var n=window.navigator;netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesRead');setLanguage((n.browserLanguage||(n.preference&&n.preference('intl.accept_languages')?n.preference('intl.accept_languages').split(',')[0]:n.language?n.language.replace(/-/,'_'):'')));
     95  if(typeof languagesMessage!='object')languagesMessage={};
     96  var i=0,msgNow,language,msg;
     97  for(;i<arguments.length;i++){
     98   msg=arguments[i];
     99   //alert(typeof msg+','+msg.constructor+','+msg);
    100   if(typeof msg=='string')msgNow=msg;
    101   else if(msg instanceof Array){
    102    language=msg[0],msg=msg[1];
    103    //alert(language+','+msg);
    104    if(language==defaultLanguage||!language)msgNow=msg;
    105    else if(msgNow){
    106     language=getLanguageAlias(language);
    107     if(typeof languagesMessage[language]!='object')languagesMessage[language]={};
    108     //alert('['+language+']['+msgNow+']='+msg);
    109     languagesMessage[language][msgNow]=msg;
    110    }
    111   }
    112  }
    113 }
    114
    115 //getMessage[generateCode.dLK]='languagesMessage,useLanguage,getLanguageAlias';
    116 function getMessage(message,language){
    117  language=getLanguageAlias(language);
    118  try{
    119   //alert(languagesMessage[language||useLanguage]);
    120   return languagesMessage[language||useLanguage][message]||message;
    121  }catch(e){return message;}
    122 }
    123
    124
    125 //	↑i18n系列	==================
    126
    127
    128
    129
    130
    131
    132 return (
    133 	CeL.locale
    134 );
    135 };
    136
    137 //===================================================
    138
    139 CeL.setup_module(module_name, code_for_including);
    140
    141 };
    142