|
46 | 46 | localeTitle: false,
|
47 | 47 | cutoff: 0,
|
48 | 48 | autoDispose: true,
|
| 49 | + lang: "en", |
49 | 50 | strings: {
|
50 |
| - prefixAgo: null, |
51 |
| - prefixFromNow: null, |
52 |
| - suffixAgo: "ago", |
53 |
| - suffixFromNow: "from now", |
54 |
| - inPast: "any moment now", |
55 |
| - seconds: "less than a minute", |
56 |
| - minute: "about a minute", |
57 |
| - minutes: "%d minutes", |
58 |
| - hour: "about an hour", |
59 |
| - hours: "about %d hours", |
60 |
| - day: "a day", |
61 |
| - days: "%d days", |
62 |
| - month: "about a month", |
63 |
| - months: "%d months", |
64 |
| - year: "about a year", |
65 |
| - years: "%d years", |
66 |
| - wordSeparator: " ", |
67 |
| - numbers: [] |
| 51 | + en: { |
| 52 | + prefixAgo: null, |
| 53 | + prefixFromNow: null, |
| 54 | + suffixAgo: "ago", |
| 55 | + suffixFromNow: "from now", |
| 56 | + inPast: "any moment now", |
| 57 | + seconds: "less than a minute", |
| 58 | + minute: "about a minute", |
| 59 | + minutes: "%d minutes", |
| 60 | + hour: "about an hour", |
| 61 | + hours: "about %d hours", |
| 62 | + day: "a day", |
| 63 | + days: "%d days", |
| 64 | + month: "about a month", |
| 65 | + months: "%d months", |
| 66 | + year: "about a year", |
| 67 | + years: "%d years", |
| 68 | + wordSeparator: " ", |
| 69 | + numbers: [] |
| 70 | + } |
68 | 71 | }
|
69 | 72 | },
|
70 | 73 |
|
71 |
| - inWords: function(distanceMillis) { |
| 74 | + inWords: function(distanceMillis, lang) { |
72 | 75 | if (!this.settings.allowPast && ! this.settings.allowFuture) {
|
73 | 76 | throw 'timeago allowPast and allowFuture settings can not both be set to false.';
|
74 | 77 | }
|
75 | 78 |
|
76 |
| - var $l = this.settings.strings; |
| 79 | + var $l = this.settings.strings[lang] || this.settings.strings[this.settings.lang] || this.settings.strings["en"] || this.settings.strings; |
77 | 80 | var prefix = $l.prefixAgo;
|
78 | 81 | var suffix = $l.suffixAgo;
|
79 | 82 | if (this.settings.allowFuture) {
|
|
84 | 87 | }
|
85 | 88 |
|
86 | 89 | if (!this.settings.allowPast && distanceMillis >= 0) {
|
87 |
| - return this.settings.strings.inPast; |
| 90 | + return $l.inPast; |
88 | 91 | }
|
89 | 92 |
|
90 | 93 | var seconds = Math.abs(distanceMillis) / 1000;
|
|
194 | 197 |
|
195 | 198 | if (!isNaN(data.datetime)) {
|
196 | 199 | if ( $s.cutoff === 0 || Math.abs(distance(data.datetime)) < $s.cutoff) {
|
197 |
| - $(this).text(inWords(data.datetime)); |
| 200 | + $(this).text(inWords(data.datetime, ($(this).attr('lang') ? $(this).attr('lang') : $t.settings.lang))); |
198 | 201 | } else {
|
199 | 202 | if ($(this).attr('title').length > 0) {
|
200 | 203 | $(this).text($(this).attr('title'));
|
|
218 | 221 | return element.data("timeago");
|
219 | 222 | }
|
220 | 223 |
|
221 |
| - function inWords(date) { |
222 |
| - return $t.inWords(distance(date)); |
| 224 | + function inWords(date, lang) { |
| 225 | + return $t.inWords(distance(date), lang); |
223 | 226 | }
|
224 | 227 |
|
225 | 228 | function distance(date) {
|
|
0 commit comments