javascript Internationalization (i18n) v1.0

easy way to perform i18n to javascript project.

visit "javascript-i18n-core" project home on google code.

Install


<head>
<script type="text/javascript" src="i18n.js"></script>
</head>
          

Configure


i18n.set({
  lang: '' / string / ISO639-1, ISO3166-1 language code, e.g. en-us, zh-tw. Default auto detect from browser.
  path: '' / string / language file's path; Default empty (same level as i18n.js)
});
          

Date and time


//e.g. Traditional Chinese
i18n.datetime(); //result is current datetime of client
          

//e.g. Traditional Chinese
i18n.datetime('2011/01/01 08:15:23'); //result is 20-11-01-01 08:15:23 in client language
          

String without variable


//e.g. Traditional Chinese
i18n._('Hello World'); //result is "哈囉! 世界";
          

String with variable(s)


//e.g. Traditional Chinese
i18n._('Nice to meet you, %1', 'John'); //result is "很高興認識你,John".
          

//e.g. Traditional Chinese
i18n._('My name is %1, I\'m %2 years old', 'John', '15'); //result is "我的名字是 John, 我今年 15 歲".
          

TOP

Language file content

            
//JSON format in Traditional Chinese
{
    //default setting
    "setting": {
        "DST": 8,
        "format": "Y 年 m 月 d 日 (l) H:i:s",
        "AM": "上午",
        "PM": "下午"
    },
    "shortMonths": ["1 月", "2 月", "3 月", "4 月", "5 月", "6 月", "7 月", "8 月", "9 月", "10 月", "11 月", "12 月"],
    "longMonths": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
    "shortDays": ["日", "一", "二", "三", "四", "五", "六"],
    "longDays": ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],

    //your text
    "Hello %1, Nice to meet you": "你好 %1, 很高興認識你",
    "My name is %1, I\'m %2 years old": "我的名字是 %1, 我今年 %2 歲"
}
            
          

Filename

filename must be same as language code. e.g. zh-tw.js, zh-cn.js...
        

Example

Traditional Chinese
zh-tw.js
Simplified Chinese
zh-cn.js

Download

Current version: 1.0

Changelog

1.0
release
MIT License

Copyright(c) 2010 essoduke.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

軟體的著作權利人依此 MIT 授權條款,將其對於軟體的著作權利授權釋出,
只要使用者踐履以下二項 MIT 授權條款敘明的義務性規定,
其即享有對此軟體程式及其相關說明文檔自由不受限制地進行利用的權利,
範圍包括「使用、重製、修改、合併、出版、散布、再授權、及販售程式重製作品」等諸多方面的應用,
而散布程式之人、更可將上述權利傳遞予其後收受程式的後手,
倘若其後收受程式之人亦服膺以下二項 MIT 授權條款的義務性規定,
則其對程式亦享有與前手運用範圍相同的同一權利。

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

散布此一軟體程式者,須將本條款其上的「著作權聲明」及以下的「免責聲明」,
內嵌於軟體程式及其重製作品的實體之中。

THE SOFTWARE IS PROVIDED 『AS IS』, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

因 MIT 軟體程式的授權模式乃是無償提供,是以在現行法律的架構下可以主張合理的免除擔保責任。
MIT 軟體的著作權人或任何的後續散布者,對於其所散布的 MIT 軟體程式皆不負任何形式上實質上的擔保責任,
明示亦或隱喻、商業利用性亦或特定目的使用性,這些均不在保障之列。利用 MIT 軟體程式的所有風險均由使用者自行擔負。
假如所使用的 MIT 程式發生缺陷性問題,使用者需自行擔負修正、改正及必要的服務支出。
MIT 軟體程式的著作權人不負任何形式上實質上的擔保責任,無論任何一般的、特殊的、偶發的、因果關係式的損害,
或是 MIT 軟體程式的不適用性,均須由使用者自行負擔。