Skip to content

Commit

Permalink
update README #13
Browse files Browse the repository at this point in the history
How to set a new locales.
  • Loading branch information
hustcc committed Sep 9, 2016
1 parent 5c834b3 commit 52d4601
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,26 @@ You can `register` you own language. All keys are needed. e.g.

```js
// the local dict example is below.
var test_local_dict = [
['just now', 'a while'],
['%s seconds ago', 'in %s seconds'],
['1 minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['1 hour ago', 'in 1 hour'],
['%s hours ago', 'in %s hours'],
['1 day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['1 week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['1 month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['1 year ago', 'in 1 year'],
['%s years ago', 'in %s years']
]
var test_local_dict = function(number, index) {
// number: the timeago / timein number;
// index: the index of array below;
return [
['just now', 'a while'],
['%s seconds ago', 'in %s seconds'],
['1 minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['1 hour ago', 'in 1 hour'],
['%s hours ago', 'in %s hours'],
['1 day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['1 week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['1 month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['1 year ago', 'in 1 year'],
['%s years ago', 'in %s years']
][index];
};

var timeago = timeago();
timeago.register('test_local', test_local_dict);
Expand Down
36 changes: 20 additions & 16 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,26 @@ timeago.setLocale('zh_CN');

```js
// 本地化的字典样式
var test_local_dict = [
['just now', 'a while'],
['%s seconds ago', 'in %s seconds'],
['1 minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['1 hour ago', 'in 1 hour'],
['%s hours ago', 'in %s hours'],
['1 day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['1 week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['1 month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['1 year ago', 'in 1 year'],
['%s years ago', 'in %s years']
]
var test_local_dict = function(number, index) {
// number: xxx 时间前 / 后的数字;
// index: 下面数组的索引号;
return [
['just now', 'a while'],
['%s seconds ago', 'in %s seconds'],
['1 minute ago', 'in 1 minute'],
['%s minutes ago', 'in %s minutes'],
['1 hour ago', 'in 1 hour'],
['%s hours ago', 'in %s hours'],
['1 day ago', 'in 1 day'],
['%s days ago', 'in %s days'],
['1 week ago', 'in 1 week'],
['%s weeks ago', 'in %s weeks'],
['1 month ago', 'in 1 month'],
['%s months ago', 'in %s months'],
['1 year ago', 'in 1 year'],
['%s years ago', 'in %s years']
][index];
};

var timeago = timeago();
timeago.register('test_local', test_local_dict);
Expand Down

0 comments on commit 52d4601

Please sign in to comment.