Skip to content

Commit

Permalink
bundle locales
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed May 20, 2018
1 parent 2797561 commit 224409c
Show file tree
Hide file tree
Showing 98 changed files with 1,171 additions and 68 deletions.
4 changes: 2 additions & 2 deletions __tests__/helper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('helper', () => {

test('diffSec', () => {
const now = new Date();
expect(diffSec(now)).toEqual(0);
expect(diffSec(now - 10000, now)).toEqual(10);
expect(diffSec(now)).toBeApproximate(0);
expect(diffSec(now - 10000, now)).toBeApproximate(10);
});

test('nextInterval', () => {
Expand Down
3 changes: 2 additions & 1 deletion __tests__/locales.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ describe('locales', () => {
});

test('register', () => {
register('fr', () => {});
register('fr', () => 'test');
expect(Locales).toContainKey('fr');
expect(Locales.fr()).toBe('test');
});
});
16 changes: 16 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,21 @@ <h3>Test for Jquery DOM ?</h3>
<p class="jquery example">
You opened this page <time class="strong">when you opened the page</time>.
</p>

<h3>Test for Locales ?</h3>
<p class="locales example">
You opened this page <time class="strong single vi">when you opened the page</time>.
<input type="button" onclick="javascript:start_vi();" value="Start." />
<input type="button" onclick="javascript:stop_vi();" value="Stop." />
</p>
</div>
<div id="footer">
Copyright &copy; 2016 How to user it, see <a href="http://timeago.org/" target="_blank" rel="nofollow">timeago.js</a>.
Updated by <a href="http://Github.com/hustcc">Hustcc</a>
</div>
<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
<script src="../dist/timeago.min.js" type="text/javascript"></script>
<script src="../dist/timeago.locales.min.js" type="text/javascript"></script>
<script src="./index.js" type="text/javascript"></script>
<script type="text/javascript">
init_test_page(); // 初始化标签上的时间
Expand Down Expand Up @@ -94,6 +102,14 @@ <h3>Test for Jquery DOM ?</h3>
function stop_single_jquery() {
timeago.cancel($('.jquery .single'));
}

function start_vi() {
timeago().render($('.vi.single'), 'vi');
}

function stop_vi() {
timeago.cancel($('.vi.single'));
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ function init_index_page() {
function init_test_page() {
$('.native time').attr('datetime', iso8601(new Date()));
$('.jquery time').attr('data-timeago', iso8601(new Date()));
$('.locales time').attr('data-timeago', iso8601(new Date()));
}

1 change: 1 addition & 0 deletions dist/timeago.locales.min.js

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions lib/lang/ar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
if (index === 0) {
return ['منذ لحظات', 'بعد لحظات'];
}

var timeStr = formatTime(Math.floor(index / 2), number);
return ['منذ' + ' ' + timeStr, 'بعد' + ' ' + timeStr];
};

var timeTypes = [['ثانية', 'ثانيتين', '%s ثوان', '%s ثانية'], // Seconds
['دقيقة', 'دقيقتين', '%s دقائق', '%s دقيقة'], // Minutes
['ساعة', 'ساعتين', '%s ساعات', '%s ساعة'], // Hours
['يوم', 'يومين', '%s أيام', '%s يوماً'], // Days
['أسبوع', 'أسبوعين', '%s أسابيع', '%s أسبوعاً'], // Weeks
['شهر', 'شهرين', '%s أشهر', '%s شهراً'], // Months
['عام', 'عامين', '%s أعوام', '%s عاماً'] // Years
];

function formatTime(type, n) {
if (n < 3) return timeTypes[type][n - 1];else if (n >= 3 && n <= 10) return timeTypes[type][2];else return timeTypes[type][3];
}
module.exports = exports['default'];
69 changes: 69 additions & 0 deletions lib/lang/be.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
switch (index) {
case 0:
return ['толькі што', 'праз некалькі секунд'];
case 1:
return [seconds(number) + ' таму', 'праз ' + seconds(number)];
case 2:
case 3:
return [minutes(number) + ' таму', 'праз ' + minutes(number)];
case 4:
case 5:
return [hours(number) + ' таму', 'праз ' + hours(number)];
case 6:
case 7:
return [days(number) + ' таму', 'праз ' + days(number)];
case 8:
case 9:
return [weeks(number) + ' таму', 'праз ' + weeks(number)];
case 10:
case 11:
return [months(number) + ' таму', 'праз ' + months(number)];
case 12:
case 13:
return [years(number) + ' таму', 'праз ' + years(number)];
default:
return ['', ''];
}
};

var seconds = formatNum.bind(null, 'секунду', '%s секунду', '%s секунды', '%s секунд'),
minutes = formatNum.bind(null, 'хвіліну', '%s хвіліну', '%s хвіліны', '%s хвілін'),
hours = formatNum.bind(null, 'гадзіну', '%s гадзіну', '%s гадзіны', '%s гадзін'),
days = formatNum.bind(null, 'дзень', '%s дзень', '%s дні', '%s дзён'),
weeks = formatNum.bind(null, 'тыдзень', '%s тыдзень', '%s тыдні', '%s тыдняў'),
months = formatNum.bind(null, 'месяц', '%s месяц', '%s месяцы', '%s месяцаў'),
years = formatNum.bind(null, 'год', '%s год', '%s гады', '%s гадоў');

;

/**
*
* @param f1 - 1
* @param f - 21, 31, ...
* @param s - 2-4, 22-24, 32-34 ...
* @param t - 5-20, 25-30, ...
* @param n
* @returns {string}
*/
function formatNum(f1, f, s, t, n) {
var n10 = n % 10,
str = t;

if (n === 1) {
str = f1;
} else if (n10 === 1 && n > 20) {
str = f;
} else if (n10 > 1 && n10 < 5 && (n > 20 || n < 10)) {
str = s;
}

return str;
}
module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/bg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['току що', 'съвсем скоро'], ['преди %s секунди', 'след %s секунди'], ['преди 1 минута', 'след 1 минута'], ['преди %s минути', 'след %s минути'], ['преди 1 час', 'след 1 час'], ['преди %s часа', 'след %s часа'], ['преди 1 ден', 'след 1 ден'], ['преди %s дни', 'след %s дни'], ['преди 1 седмица', 'след 1 седмица'], ['преди %s седмици', 'след %s седмици'], ['преди 1 месец', 'след 1 месец'], ['преди %s месеца', 'след %s месеца'], ['преди 1 година', 'след 1 година'], ['преди %s години', 'след %s години']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/ca.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['fa un moment', 'd\'aquí un moment'], ['fa %s segons', 'd\'aquí %s segons'], ['fa 1 minut', 'd\'aquí 1 minut'], ['fa %s minuts', 'd\'aquí %s minuts'], ['fa 1 hora', 'd\'aquí 1 hora'], ['fa %s hores', 'd\'aquí %s hores'], ['fa 1 dia', 'd\'aquí 1 dia'], ['fa %s dies', 'd\'aquí %s dies'], ['fa 1 setmana', 'd\'aquí 1 setmana'], ['fa %s setmanes', 'd\'aquí %s setmanes'], ['fa 1 mes', 'd\'aquí 1 mes'], ['fa %s mesos', 'd\'aquí %s mesos'], ['fa 1 any', 'd\'aquí 1 any'], ['fa %s anys', 'd\'aquí %s anys']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/da.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['for et øjeblik siden', 'om et øjeblik'], ['for %s sekunder siden', 'om %s sekunder'], ['for 1 minut siden', 'om 1 minut'], ['for %s minutter siden', 'om %s minutter'], ['for 1 time siden', 'om 1 time'], ['for %s timer siden', 'om %s timer'], ['for 1 dag siden', 'om 1 dag'], ['for %s dage siden', 'om %s dage'], ['for 1 uge siden', 'om 1 uge'], ['for %s uger siden', 'om %s uger'], ['for 1 måned siden', 'om 1 måned'], ['for %s måneder siden', 'om %s måneder'], ['for 1 år siden', 'om 1 år'], ['for %s år siden', 'om %s år']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/de.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['gerade eben', 'vor einer Weile'], ['vor %s Sekunden', 'in %s Sekunden'], ['vor 1 Minute', 'in 1 Minute'], ['vor %s Minuten', 'in %s Minuten'], ['vor 1 Stunde', 'in 1 Stunde'], ['vor %s Stunden', 'in %s Stunden'], ['vor 1 Tag', 'in 1 Tag'], ['vor %s Tagen', 'in %s Tagen'], ['vor 1 Woche', 'in 1 Woche'], ['vor %s Wochen', 'in %s Wochen'], ['vor 1 Monat', 'in 1 Monat'], ['vor %s Monaten', 'in %s Monaten'], ['vor 1 Jahr', 'in 1 Jahr'], ['vor %s Jahren', 'in %s Jahren']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/el.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['μόλις τώρα', 'σε λίγο'], ['%s δευτερόλεπτα πριν', 'σε %s δευτερόλεπτα'], ['1 λεπτό πριν', 'σε 1 λεπτό'], ['%s λεπτά πριν', 'σε %s λεπτά'], ['1 ώρα πριν', 'σε 1 ώρα'], ['%s ώρες πριν', 'σε %s ώρες'], ['1 μέρα πριν', 'σε 1 μέρα'], ['%s μέρες πριν', 'σε %s μέρες'], ['1 εβδομάδα πριν', 'σε 1 εβδομάδα'], ['%s εβδομάδες πριν', 'σε %s εβδομάδες'], ['1 μήνα πριν', 'σε 1 μήνα'], ['%s μήνες πριν', 'σε %s μήνες'], ['1 χρόνο πριν', 'σε 1 χρόνο'], ['%s χρόνια πριν', 'σε %s χρόνια']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['just now', 'right now'], ['%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];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/en_short.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['just now', 'right now'], ['%ss ago', 'in %ss'], ['1m ago', 'in 1m'], ['%sm ago', 'in %sm'], ['1h ago', 'in 1h'], ['%sh ago', 'in %sh'], ['1d ago', 'in 1d'], ['%sd ago', 'in %sd'], ['1w ago', 'in 1w'], ['%sw ago', 'in %sw'], ['1mo ago', 'in 1mo'], ['%smo ago', 'in %smo'], ['1yr ago', 'in 1yr'], ['%syr ago', 'in %syr']][index];
};

module.exports = exports['default'];
12 changes: 12 additions & 0 deletions lib/lang/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['justo ahora', 'en un rato'], ['hace %s segundos', 'en %s segundos'], ['hace 1 minuto', 'en 1 minuto'], ['hace %s minutos', 'en %s minutos'], ['hace 1 hora', 'en 1 hora'], ['hace %s horas', 'en %s horas'], ['hace 1 día', 'en 1 día'], ['hace %s días', 'en %s días'], ['hace 1 semana', 'en 1 semana'], ['hace %s semanas', 'en %s semanas'], ['hace 1 mes', 'en 1 mes'], ['hace %s meses', 'en %s meses'], ['hace 1 año', 'en 1 año'], ['hace %s años', 'en %s años']][index];
};

;
module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/eu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['orain', 'denbora bat barru'], ['duela %s segundu', '%s segundu barru'], ['duela minutu 1', 'minutu 1 barru'], ['duela %s minutu', '%s minutu barru'], ['duela ordu 1', 'ordu 1 barru'], ['duela %s ordu', '%s ordu barru'], ['duela egun 1', 'egun 1 barru'], ['duela %s egun', '%s egun barru'], ['duela aste 1', 'aste 1 barru'], ['duela %s aste', '%s aste barru'], ['duela hillabete 1', 'hillabete 1 barru'], ['duela %s hillabete', '%s hillabete barru'], ['duela urte 1', 'urte 1 barru'], ['duela %s urte', '%s urte barru']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/fa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['همین الآن', 'لحظاتی پیش'], ['%s ثانیه پیش', 'حدود %s ثانیه پیش'], ['1 دقیقه پیش', 'حدود 1 دقیقه پیش'], ['%s دقیقه پیش', 'حدود %s دقیقه پیش'], ['1 ساعت پیش', 'حدود 1 ساعت پیش'], ['%s ساعت پیش', 'حدود %s ساعت پیش'], ['1 روز پیش', 'حدود 1 روز پیش'], ['%s روز پیش', 'حدود %s روز پیش'], ['1 هفته پیش', 'حدود 1 هفته پیش'], ['%s هفته پیش', 'حدود %s هفته پیش'], ['1 ماه پیش', 'حدود 1 ماه پیش'], ['%s ماه پیش', 'حدود %s ماه پیش'], ['1 سال پیش', 'حدود 1 سال پیش'], ['%s سال پیش', 'حدود %s سال پیش']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/fi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['juuri äsken', 'juuri nyt'], ['%s sekuntia sitten', '%s sekunnin päästä'], ['minuutti sitten', 'minuutin päästä'], ['%s minuuttia sitten', '%s minuutin päästä'], ['tunti sitten', 'tunnin päästä'], ['%s tuntia sitten', '%s tunnin päästä'], ['päivä sitten', 'päivän päästä'], ['%s päivää sitten', '%s päivän päästä'], ['viikko sitten', 'viikon päästä'], ['%s viikkoa sitten', '%s viikon päästä'], ['kuukausi sitten', 'kuukauden päästä'], ['%s kuukautta sitten', '%s kuukauden päästä'], ['vuosi sitten', 'vuoden päästä'], ['%s vuotta sitten', '%s vuoden päästä']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/fr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['à l\'instant', 'dans un instant'], ['il y a %s secondes', 'dans %s secondes'], ['il y a 1 minute', 'dans 1 minute'], ['il y a %s minutes', 'dans %s minutes'], ['il y a 1 heure', 'dans 1 heure'], ['il y a %s heures', 'dans %s heures'], ['il y a 1 jour', 'dans 1 jour'], ['il y a %s jours', 'dans %s jours'], ['il y a 1 semaine', 'dans 1 semaine'], ['il y a %s semaines', 'dans %s semaines'], ['il y a 1 mois', 'dans 1 mois'], ['il y a %s mois', 'dans %s mois'], ['il y a 1 an', 'dans 1 an'], ['il y a %s ans', 'dans %s ans']][index];
};

module.exports = exports['default'];
12 changes: 12 additions & 0 deletions lib/lang/gl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['xusto agora', 'daquí a un pouco'], ['hai %s segundos', 'en %s segundos'], ['hai 1 minuto', 'nun minuto'], ['hai %s minutos', 'en %s minutos'], ['hai 1 hora', 'nunha hora'], ['hai %s horas', 'en %s horas'], ['hai 1 día', 'nun día'], ['hai %s días', 'en %s días'], ['hai 1 semana', 'nunha semana'], ['hai %s semanas', 'en %s semanas'], ['hai 1 mes', 'nun mes'], ['hai %s meses', 'en %s meses'], ['hai 1 ano', 'nun ano'], ['hai %s anos', 'en %s anos']][index];
};

;
module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/he.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['זה עתה', 'עכשיו'], ['לפני %s שניות', 'בעוד %s שניות'], ['לפני דקה', 'בעוד דקה'], ['לפני %s דקות', 'בעוד %s דקות'], ['לפני שעה', 'בעוד שעה'], ['לפני %s שעות', 'בעוד %s שעות'], ['אתמול', 'מחר'], ['לפני %s ימים', 'בעוד %s ימים'], ['לפני שבוע', 'בעוד שבוע'], ['לפני %s שבועות', 'בעוד %s שבועות'], ['לפני חודש', 'בעוד חודש'], ['לפני %s חודשים', 'בעוד %s חודשים'], ['לפני שנה', 'בעוד שנה'], ['לפני %s שנים', 'בעוד %s שנים']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/hu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['éppen most', 'éppen most'], ['%s másodperce', '%s másodpercen belül'], ['1 perce', '1 percen belül'], ['%s perce', '%s percen belül'], ['1 órája', '1 órán belül'], ['%s órája', '%s órán belül'], ['1 napja', '1 napon belül'], ['%s napja', '%s napon belül'], ['1 hete', '1 héten belül'], ['%s hete', '%s héten belül'], ['1 hónapja', '1 hónapon belül'], ['%s hónapja', '%s hónapon belül'], ['1 éve', '1 éven belül'], ['%s éve', '%s éven belül']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/in_BG.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['এইমাত্র', 'একটা সময়'], ['%s সেকেন্ড আগে', '%s এর সেকেন্ডের মধ্যে'], ['1 মিনিট আগে', '1 মিনিটে'], ['%s এর মিনিট আগে', '%s এর মিনিটের মধ্যে'], ['1 ঘন্টা আগে', '1 ঘন্টা'], ['%s ঘণ্টা আগে', '%s এর ঘন্টার মধ্যে'], ['1 দিন আগে', '1 দিনের মধ্যে'], ['%s এর দিন আগে', '%s এর দিন'], ['1 সপ্তাহ আগে', '1 সপ্তাহের মধ্যে'], ['%s এর সপ্তাহ আগে', '%s সপ্তাহের মধ্যে'], ['1 মাস আগে', '1 মাসে'], ['%s মাস আগে', '%s মাসে'], ['1 বছর আগে', '1 বছরের মধ্যে'], ['%s বছর আগে', '%s বছরে']][index];
};

module.exports = exports['default'];
11 changes: 11 additions & 0 deletions lib/lang/in_HI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (number, index) {
return [['अभी', 'कुछ समय'], ['%s सेकंड पहले', '%s सेकंड में'], ['1 मिनट पहले', '1 मिनट में'], ['%s मिनट पहले', '%s मिनट में'], ['1 घंटे पहले', '1 घंटे में'], ['%s घंटे पहले', '%s घंटे में'], ['1 दिन पहले', '1 दिन में'], ['%s दिन पहले', '%s दिनों में'], ['1 सप्ताह पहले', '1 सप्ताह में'], ['%s हफ्ते पहले', '%s हफ्तों में'], ['1 महीने पहले', '1 महीने में'], ['%s महीने पहले', '%s महीनों में'], ['1 साल पहले', '1 साल में'], ['%s साल पहले', '%s साल में']][index];
};

module.exports = exports['default'];
Loading

0 comments on commit 224409c

Please sign in to comment.