javascript-i18n-core


javascript internationalization solution

About

javascript-i18n-core is an easy way to perform i18n to your javascript project without any library.

Moved to GitHub https://github.com/essoduke/javascript-i18n-core

Installation

put script into <head>...</head> ```

```

Configure

i18n.set({ lang: 'en-us, zh-tw...', path: '', });

| option | description | |:-----------|:----------------| | lang | valid ISO 639-1, ISO 3166-1 language code. | | path |language file path. default empty(same level as core js) |

Usage

date and time

``` i18n.datetime(); //return current datetime in 'YYYY-mm-dd h:i:s' format.

i18n.datetime('2011/01/01 00:00:00'); //return '2011/01/01 00:00:00' in customize format. ```

string without variables

i18n._('your message');

string with variables

``` i18n._('string with variables %1 %2...', param1, param2...);

e.g.

i18n._('My name is %1, I\'m %2 years old', 'John', '15'); ```

Language File format

  • language file content must be valid in standard JSON format(UTF-8).
  • filename must be same as language code. e.g. zh-tw.js, zh-cn.js...

Default setting

{ "setting": { "DST": -4, "format": "D, d F Y H:i:s", //datetime format like PHP date() "AM": "AM", "PM": "PM" }, "shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], "longMonths": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], "shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], "longDays": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] }

Chinese(Traditional)

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

//customize string    
"Hello World": "哈囉! 世界",
"Nice to meet you, %1": "很高興認識你,%1",
"My name is %1, I'm %2 years old": "我的名字是 %1,我今年 %2 歲"

}

```

Online Demo

http://app.essoduke.org/i18n/

Project Information

The project was created on Jun 22, 2011.

Labels:
JavaScript I18n