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 CeL.setup_module('application.locale', 17 function(library_namespace, load_arguments) { 18 19 20 // nothing required 21 22 23 24 25 26 /** 27 * null module constructor 28 * @class locale 的 functions 29 */ 30 CeL.application.locale 31 = function() { 32 // null module constructor 33 }; 34 35 /** 36 * for JSDT: 有 prototype 才會將之當作 Class 37 */ 38 CeL.application.locale 39 .prototype = { 40 }; 41 42 43 44 45 46 // i18n系列 ================== 47 48 /* setup message of various languages for i18n (internationalization) 49 var languagesMessage={},defaultLanguage,useLanguage,languageAlias; 50 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'); 51 */ 52 //get_language_alias[generateCode.dLK]='languageAlias,existLanguageAlias'; 53 function get_language_alias(language) { 54 if (existLanguageAlias(language)) 55 language = languageAlias[language]; 56 return language; 57 } 58 59 //existLanguageAlias[generateCode.dLK]='languageAlias'; 60 function existLanguageAlias(language) { 61 return language && language in languageAlias; 62 } 63 64 // (language, if you want to setup defaultLanguage as well) 65 //set_language[generateCode.dLK]='get_language_alias,defaultLanguage,useLanguage'; 66 function set_language(language, mode) { 67 language = get_language_alias(language); 68 if (mode) 69 defaultLanguage = language; 70 else 71 useLanguage = language; 72 return useLanguage; 73 } 74 75 // setMessage(messageIndex1,[local,message],[local,message],messageIndex2,[local,message],[local,message],..) 76 //setMessage[generateCode.dLK]='languagesMessage,defaultLanguage,get_language_alias'; 77 function setMessage(){ 78 //if(!defaultLanguage)defaultLanguage='en_US'; 79 // n.preference('intl.charset.default') http://chaichan.hp.infoseek.co.jp/qa3500/qa3803.htm http://articles.techrepublic.com.com/5100-22-5069931.html 80 // http://forum.mozilla.gr.jp/?mode=al2&namber=5608&rev=&&KLOG=39 81 // navigator.language=general.useragent.locale @ about:config 82 // var n=window.navigator;netscape.security.PrivilegeManager.enablePrivilege('UniversalPreferencesRead');set_language((n.browserLanguage||(n.preference&&n.preference('intl.accept_languages')?n.preference('intl.accept_languages').split(',')[0]:n.language?n.language.replace(/-/,'_'):''))); 83 if(typeof languagesMessage!='object')languagesMessage={}; 84 var i=0,msgNow,language,msg; 85 for(;i<arguments.length;i++){ 86 msg=arguments[i]; 87 //alert(typeof msg+','+msg.constructor+','+msg); 88 if(typeof msg=='string')msgNow=msg; 89 else if(msg instanceof Array){ 90 language=msg[0],msg=msg[1]; 91 //alert(language+','+msg); 92 if(language==defaultLanguage||!language)msgNow=msg; 93 else if(msgNow){ 94 language=get_language_alias(language); 95 if(typeof languagesMessage[language]!='object')languagesMessage[language]={}; 96 //alert('['+language+']['+msgNow+']='+msg); 97 languagesMessage[language][msgNow]=msg; 98 } 99 } 100 } 101 } 102 103 //get_local_message[generateCode.dLK]='languagesMessage,useLanguage,get_language_alias'; 104 function get_local_message(message, language) { 105 language = get_language_alias(language); 106 try { 107 // alert(languagesMessage[language||useLanguage]); 108 return languagesMessage[language || useLanguage][message] 109 || message; 110 } catch (e) { 111 return message; 112 } 113 } 114 115 116 // ↑i18n系列 ================== 117 118 119 120 121 122 return ( 123 CeL.application.locale 124 ); 125 } 126 127 128 ); 129 130