From bdff08ec4f5c9ec8047c8abe98e33b6bce3fb67e Mon Sep 17 00:00:00 2001 From: Jan Graichen Date: Sat, 13 Jun 2020 19:15:42 +0200 Subject: [PATCH] Support multiple locales concurrent This commit extends the plugin to support loading and using mutliple locales at the same time. All strings are stored with their language code. The plugins gets a new `lang` setting denoting the default locale. For each HTML tag, the plugin will lookup `lang` attribute from the tag, the configured default lang, or fallback to english. It will use the `strings` object directly, if no lang key is found at all, therefore it supports loading and running with older or custom locale files that are directly assigning strings. --- jquery.timeago.js | 51 ++++++++------- locales/jquery.timeago.af.js | 2 +- locales/jquery.timeago.am.js | 2 +- locales/jquery.timeago.ar.js | 2 +- locales/jquery.timeago.az-short.js | 2 +- locales/jquery.timeago.az.js | 2 +- locales/jquery.timeago.be.js | 2 +- locales/jquery.timeago.bg.js | 2 +- locales/jquery.timeago.bs.js | 2 +- locales/jquery.timeago.ca.js | 2 +- locales/jquery.timeago.cs.js | 2 +- locales/jquery.timeago.cy.js | 2 +- locales/jquery.timeago.da.js | 2 +- locales/jquery.timeago.de-short.js | 2 +- locales/jquery.timeago.de.js | 2 +- locales/jquery.timeago.dv.js | 2 +- locales/jquery.timeago.el.js | 2 +- locales/jquery.timeago.en-short.js | 2 +- locales/jquery.timeago.en.js | 2 +- locales/jquery.timeago.eo.js | 2 +- locales/jquery.timeago.es-short.js | 2 +- locales/jquery.timeago.es.js | 2 +- locales/jquery.timeago.et.js | 2 +- locales/jquery.timeago.eu.js | 2 +- locales/jquery.timeago.fa-short.js | 2 +- locales/jquery.timeago.fa.js | 2 +- locales/jquery.timeago.fi.js | 2 +- locales/jquery.timeago.fr-short.js | 2 +- locales/jquery.timeago.fr.js | 2 +- locales/jquery.timeago.gl.js | 2 +- locales/jquery.timeago.he.js | 2 +- locales/jquery.timeago.hr.js | 2 +- locales/jquery.timeago.hu.js | 2 +- locales/jquery.timeago.hy.js | 2 +- locales/jquery.timeago.id.js | 2 +- locales/jquery.timeago.is.js | 2 +- locales/jquery.timeago.it-short.js | 2 +- locales/jquery.timeago.it.js | 2 +- locales/jquery.timeago.ja.js | 2 +- locales/jquery.timeago.jv.js | 2 +- locales/jquery.timeago.ka.js | 2 +- locales/jquery.timeago.ko.js | 2 +- locales/jquery.timeago.ky.js | 2 +- locales/jquery.timeago.lt.js | 2 +- locales/jquery.timeago.lv.js | 2 +- locales/jquery.timeago.mk.js | 2 +- locales/jquery.timeago.nl.js | 2 +- locales/jquery.timeago.no.js | 2 +- locales/jquery.timeago.pl.js | 2 +- locales/jquery.timeago.pt-br-short.js | 2 +- locales/jquery.timeago.pt-br.js | 2 +- locales/jquery.timeago.pt-short.js | 2 +- locales/jquery.timeago.pt.js | 2 +- locales/jquery.timeago.ro.js | 2 +- locales/jquery.timeago.rs.js | 2 +- locales/jquery.timeago.ru.js | 2 +- locales/jquery.timeago.rw.js | 2 +- locales/jquery.timeago.si.js | 2 +- locales/jquery.timeago.sk.js | 2 +- locales/jquery.timeago.sl.js | 2 +- locales/jquery.timeago.sq.js | 2 +- locales/jquery.timeago.sr.js | 2 +- locales/jquery.timeago.sv.js | 2 +- locales/jquery.timeago.th.js | 2 +- locales/jquery.timeago.tr-short.js | 2 +- locales/jquery.timeago.tr.js | 2 +- locales/jquery.timeago.uk.js | 2 +- locales/jquery.timeago.ur.js | 2 +- locales/jquery.timeago.uz.js | 2 +- locales/jquery.timeago.vi.js | 2 +- locales/jquery.timeago.zh-CN.js | 2 +- locales/jquery.timeago.zh-TW.js | 2 +- test/index.html | 30 +++++++++ test/test_helpers.js | 93 ++++++++++++++++++++++----- 74 files changed, 204 insertions(+), 112 deletions(-) diff --git a/jquery.timeago.js b/jquery.timeago.js index ec80c323..d54aefaf 100644 --- a/jquery.timeago.js +++ b/jquery.timeago.js @@ -46,34 +46,37 @@ localeTitle: false, cutoff: 0, autoDispose: true, + lang: "en", strings: { - prefixAgo: null, - prefixFromNow: null, - suffixAgo: "ago", - suffixFromNow: "from now", - inPast: "any moment now", - seconds: "less than a minute", - minute: "about a minute", - minutes: "%d minutes", - hour: "about an hour", - hours: "about %d hours", - day: "a day", - days: "%d days", - month: "about a month", - months: "%d months", - year: "about a year", - years: "%d years", - wordSeparator: " ", - numbers: [] + en: { + prefixAgo: null, + prefixFromNow: null, + suffixAgo: "ago", + suffixFromNow: "from now", + inPast: "any moment now", + seconds: "less than a minute", + minute: "about a minute", + minutes: "%d minutes", + hour: "about an hour", + hours: "about %d hours", + day: "a day", + days: "%d days", + month: "about a month", + months: "%d months", + year: "about a year", + years: "%d years", + wordSeparator: " ", + numbers: [] + } } }, - inWords: function(distanceMillis) { + inWords: function(distanceMillis, lang) { if (!this.settings.allowPast && ! this.settings.allowFuture) { throw 'timeago allowPast and allowFuture settings can not both be set to false.'; } - var $l = this.settings.strings; + var $l = this.settings.strings[lang] || this.settings.strings[this.settings.lang] || this.settings.strings["en"] || this.settings.strings; var prefix = $l.prefixAgo; var suffix = $l.suffixAgo; if (this.settings.allowFuture) { @@ -84,7 +87,7 @@ } if (!this.settings.allowPast && distanceMillis >= 0) { - return this.settings.strings.inPast; + return $l.inPast; } var seconds = Math.abs(distanceMillis) / 1000; @@ -194,7 +197,7 @@ if (!isNaN(data.datetime)) { if ( $s.cutoff === 0 || Math.abs(distance(data.datetime)) < $s.cutoff) { - $(this).text(inWords(data.datetime)); + $(this).text(inWords(data.datetime, ($(this).attr('lang') ? $(this).attr('lang') : $t.settings.lang))); } else { if ($(this).attr('title').length > 0) { $(this).text($(this).attr('title')); @@ -218,8 +221,8 @@ return element.data("timeago"); } - function inWords(date) { - return $t.inWords(distance(date)); + function inWords(date, lang) { + return $t.inWords(distance(date), lang); } function distance(date) { diff --git a/locales/jquery.timeago.af.js b/locales/jquery.timeago.af.js index 817a7fa5..d908549e 100644 --- a/locales/jquery.timeago.af.js +++ b/locales/jquery.timeago.af.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Afrikaans - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["af"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "gelede", diff --git a/locales/jquery.timeago.am.js b/locales/jquery.timeago.am.js index 65502c39..b933a9ff 100644 --- a/locales/jquery.timeago.am.js +++ b/locales/jquery.timeago.am.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Amharic - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["am"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "በፊት", diff --git a/locales/jquery.timeago.ar.js b/locales/jquery.timeago.ar.js index 14cd18f2..41fe9eb2 100644 --- a/locales/jquery.timeago.ar.js +++ b/locales/jquery.timeago.ar.js @@ -11,7 +11,7 @@ return a[plural=n===0 ? 0 : n===1 ? 1 : n===2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5]; } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ar"] = { prefixAgo: "منذ", prefixFromNow: "بعد", suffixAgo: null, diff --git a/locales/jquery.timeago.az-short.js b/locales/jquery.timeago.az-short.js index a1d5740e..81022bb1 100644 --- a/locales/jquery.timeago.az-short.js +++ b/locales/jquery.timeago.az-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Azerbaijani shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["az-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.az.js b/locales/jquery.timeago.az.js index 8332c41c..6a1f4098 100644 --- a/locales/jquery.timeago.az.js +++ b/locales/jquery.timeago.az.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Azerbaijani - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["az"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: 'əvvəl', diff --git a/locales/jquery.timeago.be.js b/locales/jquery.timeago.be.js index 50efb8cd..24cc988c 100644 --- a/locales/jquery.timeago.be.js +++ b/locales/jquery.timeago.be.js @@ -23,7 +23,7 @@ } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["be"] = { prefixAgo: null, prefixFromNow: "праз", suffixAgo: "таму", diff --git a/locales/jquery.timeago.bg.js b/locales/jquery.timeago.bg.js index a3bd343a..4052d832 100644 --- a/locales/jquery.timeago.bg.js +++ b/locales/jquery.timeago.bg.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Bulgarian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["bg"] = { prefixAgo: "преди", prefixFromNow: "след", suffixAgo: null, diff --git a/locales/jquery.timeago.bs.js b/locales/jquery.timeago.bs.js index cbb17806..a6e2a89a 100644 --- a/locales/jquery.timeago.bs.js +++ b/locales/jquery.timeago.bs.js @@ -20,7 +20,7 @@ } }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["bs"] = { prefixAgo: "prije", prefixFromNow: "za", suffixAgo: null, diff --git a/locales/jquery.timeago.ca.js b/locales/jquery.timeago.ca.js index e4cb5cab..9e3e850e 100644 --- a/locales/jquery.timeago.ca.js +++ b/locales/jquery.timeago.ca.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Catalan - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ca"] = { prefixAgo: "fa", prefixFromNow: "d'aquí", suffixAgo: null, diff --git a/locales/jquery.timeago.cs.js b/locales/jquery.timeago.cs.js index b940f694..d0d76d1d 100644 --- a/locales/jquery.timeago.cs.js +++ b/locales/jquery.timeago.cs.js @@ -13,7 +13,7 @@ return a[d>=0 ? 0 : a.length===2 || n<5 ? 1 : 2]; } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["cs"] = { prefixAgo: 'před', prefixFromNow: 'za', suffixAgo: null, diff --git a/locales/jquery.timeago.cy.js b/locales/jquery.timeago.cy.js index 4c514a8d..fa7fc713 100644 --- a/locales/jquery.timeago.cy.js +++ b/locales/jquery.timeago.cy.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Welsh - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["cy"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "yn ôl", diff --git a/locales/jquery.timeago.da.js b/locales/jquery.timeago.da.js index 236c34c4..85a6d716 100644 --- a/locales/jquery.timeago.da.js +++ b/locales/jquery.timeago.da.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Danish - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["da"] = { prefixAgo: "for", prefixFromNow: "om", suffixAgo: "siden", diff --git a/locales/jquery.timeago.de-short.js b/locales/jquery.timeago.de-short.js index 15b446e3..bdf8c80e 100644 --- a/locales/jquery.timeago.de-short.js +++ b/locales/jquery.timeago.de-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // German shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["de-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.de.js b/locales/jquery.timeago.de.js index 9cdde887..12fca0bf 100644 --- a/locales/jquery.timeago.de.js +++ b/locales/jquery.timeago.de.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // German - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["de"] = { prefixAgo: "vor", prefixFromNow: "in", suffixAgo: "", diff --git a/locales/jquery.timeago.dv.js b/locales/jquery.timeago.dv.js index 0d70a493..68ff6582 100644 --- a/locales/jquery.timeago.dv.js +++ b/locales/jquery.timeago.dv.js @@ -10,7 +10,7 @@ /** * Dhivehi time in Thaana for timeago.js **/ - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["dv"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "ކުރިން", diff --git a/locales/jquery.timeago.el.js b/locales/jquery.timeago.el.js index 2db9ebea..cdb5778f 100644 --- a/locales/jquery.timeago.el.js +++ b/locales/jquery.timeago.el.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Greek - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["el"] = { prefixAgo: "πριν", prefixFromNow: "σε", suffixAgo: "", diff --git a/locales/jquery.timeago.en-short.js b/locales/jquery.timeago.en-short.js index 157aaa48..14468eea 100644 --- a/locales/jquery.timeago.en-short.js +++ b/locales/jquery.timeago.en-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // English shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["en-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.en.js b/locales/jquery.timeago.en.js index 8ca50aff..4271fb31 100644 --- a/locales/jquery.timeago.en.js +++ b/locales/jquery.timeago.en.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // English (Template) - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["en"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "ago", diff --git a/locales/jquery.timeago.eo.js b/locales/jquery.timeago.eo.js index 76ecd7c7..b0bf4ff4 100644 --- a/locales/jquery.timeago.eo.js +++ b/locales/jquery.timeago.eo.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // English (Template) -> Esperanto - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["eo"] = { prefixAgo: "antaŭ", prefixFromNow: null, suffixAgo: null, diff --git a/locales/jquery.timeago.es-short.js b/locales/jquery.timeago.es-short.js index f762a06d..deb62570 100644 --- a/locales/jquery.timeago.es-short.js +++ b/locales/jquery.timeago.es-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Spanish shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["es-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.es.js b/locales/jquery.timeago.es.js index 0785b3f4..c7fb1d16 100644 --- a/locales/jquery.timeago.es.js +++ b/locales/jquery.timeago.es.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Spanish - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["es"] = { prefixAgo: "hace", prefixFromNow: "dentro de", suffixAgo: "", diff --git a/locales/jquery.timeago.et.js b/locales/jquery.timeago.et.js index ac2461ec..bf0444d8 100644 --- a/locales/jquery.timeago.et.js +++ b/locales/jquery.timeago.et.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Estonian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["et"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "tagasi", diff --git a/locales/jquery.timeago.eu.js b/locales/jquery.timeago.eu.js index 5c2c32c7..352b2428 100644 --- a/locales/jquery.timeago.eu.js +++ b/locales/jquery.timeago.eu.js @@ -7,7 +7,7 @@ factory(jQuery); } }(function (jQuery) { - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["eu"] = { prefixAgo: "duela", prefixFromNow: "hemendik", suffixAgo: "", diff --git a/locales/jquery.timeago.fa-short.js b/locales/jquery.timeago.fa-short.js index c8b5fc4e..bd2e1f44 100644 --- a/locales/jquery.timeago.fa-short.js +++ b/locales/jquery.timeago.fa-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // persian shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["fa-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.fa.js b/locales/jquery.timeago.fa.js index d3495aa3..5d08cdf5 100644 --- a/locales/jquery.timeago.fa.js +++ b/locales/jquery.timeago.fa.js @@ -10,7 +10,7 @@ // Persian // Use DIR attribute for RTL text in Persian Language for ABBR tag . // By MB.seifollahi@gmail.com - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["fa"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "پیش", diff --git a/locales/jquery.timeago.fi.js b/locales/jquery.timeago.fi.js index b5f7e696..1eb436bc 100644 --- a/locales/jquery.timeago.fi.js +++ b/locales/jquery.timeago.fi.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Finnish - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["fi"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "sitten", diff --git a/locales/jquery.timeago.fr-short.js b/locales/jquery.timeago.fr-short.js index a116eada..fa1d5cbb 100644 --- a/locales/jquery.timeago.fr-short.js +++ b/locales/jquery.timeago.fr-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // French shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["fr-short"] = { prefixAgo: "il y a", prefixFromNow: "d'ici", seconds: "moins d'une minute", diff --git a/locales/jquery.timeago.fr.js b/locales/jquery.timeago.fr.js index 1bb052aa..1617d855 100644 --- a/locales/jquery.timeago.fr.js +++ b/locales/jquery.timeago.fr.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // French - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["fr"] = { // environ ~= about, it's optional prefixAgo: "il y a", prefixFromNow: "d'ici", diff --git a/locales/jquery.timeago.gl.js b/locales/jquery.timeago.gl.js index 277bbf70..6f05b1fa 100644 --- a/locales/jquery.timeago.gl.js +++ b/locales/jquery.timeago.gl.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Galician - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["gl"] = { prefixAgo: "hai", prefixFromNow: "dentro de", suffixAgo: "", diff --git a/locales/jquery.timeago.he.js b/locales/jquery.timeago.he.js index 2cd31ab6..7574450e 100644 --- a/locales/jquery.timeago.he.js +++ b/locales/jquery.timeago.he.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Hebrew - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["he"] = { prefixAgo: "לפני", prefixFromNow: "עוד", seconds: "פחות מדקה", diff --git a/locales/jquery.timeago.hr.js b/locales/jquery.timeago.hr.js index bd142979..da904eaa 100644 --- a/locales/jquery.timeago.hr.js +++ b/locales/jquery.timeago.hr.js @@ -20,7 +20,7 @@ } }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["hr"] = { prefixAgo: "prije", prefixFromNow: "za", suffixAgo: null, diff --git a/locales/jquery.timeago.hu.js b/locales/jquery.timeago.hu.js index 0009de9e..63a41459 100644 --- a/locales/jquery.timeago.hu.js +++ b/locales/jquery.timeago.hu.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Hungarian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["hu"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: null, diff --git a/locales/jquery.timeago.hy.js b/locales/jquery.timeago.hy.js index 3f0de6e7..680f24b3 100644 --- a/locales/jquery.timeago.hy.js +++ b/locales/jquery.timeago.hy.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Armenian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["hy"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "առաջ", diff --git a/locales/jquery.timeago.id.js b/locales/jquery.timeago.id.js index ca530ccf..6d8db877 100644 --- a/locales/jquery.timeago.id.js +++ b/locales/jquery.timeago.id.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Indonesian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["id"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "yang lalu", diff --git a/locales/jquery.timeago.is.js b/locales/jquery.timeago.is.js index e3d4b1fd..adb75b2c 100644 --- a/locales/jquery.timeago.is.js +++ b/locales/jquery.timeago.is.js @@ -7,7 +7,7 @@ factory(jQuery); } }(function (jQuery) { - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["is"] = { prefixAgo: "fyrir", prefixFromNow: "eftir", suffixAgo: "síðan", diff --git a/locales/jquery.timeago.it-short.js b/locales/jquery.timeago.it-short.js index f1da0cc1..03f4b036 100644 --- a/locales/jquery.timeago.it-short.js +++ b/locales/jquery.timeago.it-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Italian shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["it-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.it.js b/locales/jquery.timeago.it.js index 32ee9438..32cb2016 100644 --- a/locales/jquery.timeago.it.js +++ b/locales/jquery.timeago.it.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Italian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["it"] = { prefixAgo: null, prefixFromNow: "fra", suffixAgo: "fa", diff --git a/locales/jquery.timeago.ja.js b/locales/jquery.timeago.ja.js index 30f3308c..631bef70 100644 --- a/locales/jquery.timeago.ja.js +++ b/locales/jquery.timeago.ja.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Japanese - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ja"] = { prefixAgo: "", prefixFromNow: "今から", suffixAgo: "前", diff --git a/locales/jquery.timeago.jv.js b/locales/jquery.timeago.jv.js index 0344053d..d2a19f5c 100644 --- a/locales/jquery.timeago.jv.js +++ b/locales/jquery.timeago.jv.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Javanesse (Boso Jowo) - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["jv"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "kepungkur", diff --git a/locales/jquery.timeago.ka.js b/locales/jquery.timeago.ka.js index ff97dd77..10cc684f 100644 --- a/locales/jquery.timeago.ka.js +++ b/locales/jquery.timeago.ka.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // English (Template) - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ka"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "ის წინ", diff --git a/locales/jquery.timeago.ko.js b/locales/jquery.timeago.ko.js index 23d1d378..056dab07 100644 --- a/locales/jquery.timeago.ko.js +++ b/locales/jquery.timeago.ko.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Korean - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ko"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "전", diff --git a/locales/jquery.timeago.ky.js b/locales/jquery.timeago.ky.js index 58dba293..da3d521e 100644 --- a/locales/jquery.timeago.ky.js +++ b/locales/jquery.timeago.ky.js @@ -22,7 +22,7 @@ } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ky"] = { prefixAgo: null, prefixFromNow: "через", suffixAgo: "мурун", diff --git a/locales/jquery.timeago.lt.js b/locales/jquery.timeago.lt.js index 2079fccd..a359c8ff 100644 --- a/locales/jquery.timeago.lt.js +++ b/locales/jquery.timeago.lt.js @@ -8,7 +8,7 @@ } }(function (jQuery) { //Lithuanian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["lt"] = { prefixAgo: "prieš", prefixFromNow: null, suffixAgo: null, diff --git a/locales/jquery.timeago.lv.js b/locales/jquery.timeago.lv.js index 855d1a4d..b980e57d 100644 --- a/locales/jquery.timeago.lv.js +++ b/locales/jquery.timeago.lv.js @@ -8,7 +8,7 @@ } }(function (jQuery) { //Latvian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["lv"] = { prefixAgo: "pirms", prefixFromNow: null, suffixAgo: null, diff --git a/locales/jquery.timeago.mk.js b/locales/jquery.timeago.mk.js index 301a5da8..22180e09 100644 --- a/locales/jquery.timeago.mk.js +++ b/locales/jquery.timeago.mk.js @@ -9,7 +9,7 @@ }(function (jQuery) { // Macedonian (function() { - jQuery.timeago.settings.strings={ + jQuery.timeago.settings.strings["mk"]={ prefixAgo: "пред", prefixFromNow: "за", suffixAgo: null, diff --git a/locales/jquery.timeago.nl.js b/locales/jquery.timeago.nl.js index 2c5de89c..b1210dd6 100644 --- a/locales/jquery.timeago.nl.js +++ b/locales/jquery.timeago.nl.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Dutch - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["nl"] = { prefixAgo: null, prefixFromNow: "over", suffixAgo: "geleden", diff --git a/locales/jquery.timeago.no.js b/locales/jquery.timeago.no.js index c896337c..63035a50 100644 --- a/locales/jquery.timeago.no.js +++ b/locales/jquery.timeago.no.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Norwegian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["no"] = { prefixAgo: "for", prefixFromNow: "om", suffixAgo: "siden", diff --git a/locales/jquery.timeago.pl.js b/locales/jquery.timeago.pl.js index 48427846..d2034057 100644 --- a/locales/jquery.timeago.pl.js +++ b/locales/jquery.timeago.pl.js @@ -19,7 +19,7 @@ } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["pl"] = { prefixAgo: null, prefixFromNow: "za", suffixAgo: "temu", diff --git a/locales/jquery.timeago.pt-br-short.js b/locales/jquery.timeago.pt-br-short.js index f7cd7e8d..9da7b600 100644 --- a/locales/jquery.timeago.pt-br-short.js +++ b/locales/jquery.timeago.pt-br-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Portuguese Brasil shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["pt-br-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.pt-br.js b/locales/jquery.timeago.pt-br.js index a8701a88..586f55d1 100644 --- a/locales/jquery.timeago.pt-br.js +++ b/locales/jquery.timeago.pt-br.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Brazilian Portuguese - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["pt-br"] = { prefixAgo: "há", prefixFromNow: "em", suffixAgo: null, diff --git a/locales/jquery.timeago.pt-short.js b/locales/jquery.timeago.pt-short.js index 0b146a79..043bac89 100644 --- a/locales/jquery.timeago.pt-short.js +++ b/locales/jquery.timeago.pt-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Portuguese shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["pt-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.pt.js b/locales/jquery.timeago.pt.js index e060bbfb..043725a1 100644 --- a/locales/jquery.timeago.pt.js +++ b/locales/jquery.timeago.pt.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Portuguese - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["pt"] = { prefixAgo: "há", prefixFromNow: "daqui a", seconds: "menos de um minuto", diff --git a/locales/jquery.timeago.ro.js b/locales/jquery.timeago.ro.js index feda3aad..ad715209 100644 --- a/locales/jquery.timeago.ro.js +++ b/locales/jquery.timeago.ro.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Romanian - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ro"] = { prefixAgo: "acum", prefixFromNow: "peste", suffixAgo: "", diff --git a/locales/jquery.timeago.rs.js b/locales/jquery.timeago.rs.js index b9e51882..b81d4282 100644 --- a/locales/jquery.timeago.rs.js +++ b/locales/jquery.timeago.rs.js @@ -20,7 +20,7 @@ } }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["rs"] = { prefixAgo: "pre", prefixFromNow: "za", suffixAgo: null, diff --git a/locales/jquery.timeago.ru.js b/locales/jquery.timeago.ru.js index 4ff3f8d3..62a2eb8c 100644 --- a/locales/jquery.timeago.ru.js +++ b/locales/jquery.timeago.ru.js @@ -23,7 +23,7 @@ } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ru"] = { prefixAgo: null, prefixFromNow: "через", suffixAgo: "назад", diff --git a/locales/jquery.timeago.rw.js b/locales/jquery.timeago.rw.js index 50119e1e..eb31452d 100644 --- a/locales/jquery.timeago.rw.js +++ b/locales/jquery.timeago.rw.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Kinyarwanda - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["rw"] = { prefixAgo: "hashize", prefixFromNow: "mu", suffixAgo: null, diff --git a/locales/jquery.timeago.si.js b/locales/jquery.timeago.si.js index 6fa215e9..c99edeff 100644 --- a/locales/jquery.timeago.si.js +++ b/locales/jquery.timeago.si.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Sinhalese (SI) - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["si"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "පෙර", diff --git a/locales/jquery.timeago.sk.js b/locales/jquery.timeago.sk.js index e28ab7c9..67d5212f 100644 --- a/locales/jquery.timeago.sk.js +++ b/locales/jquery.timeago.sk.js @@ -13,7 +13,7 @@ return a[d>=0 ? 0 : a.length===2 || n<5 ? 1 : 2]; } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["sk"] = { prefixAgo: 'pred', prefixFromNow: 'o', suffixAgo: null, diff --git a/locales/jquery.timeago.sl.js b/locales/jquery.timeago.sl.js index 9f0329ac..61664af4 100644 --- a/locales/jquery.timeago.sl.js +++ b/locales/jquery.timeago.sl.js @@ -12,7 +12,7 @@ return a[n%100===1 ? 1 : n%100===2 ? 2 : n%100===3 || n%100===4 ? 3 : 0]; }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["sl"] = { prefixAgo: null, prefixFromNow: "čez", suffixAgo: "nazaj", diff --git a/locales/jquery.timeago.sq.js b/locales/jquery.timeago.sq.js index cb8ae703..a1b779ed 100644 --- a/locales/jquery.timeago.sq.js +++ b/locales/jquery.timeago.sq.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Albanian SQ - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["sq"] = { suffixAgo: "më parë", suffixFromNow: "tani", seconds: "më pak se një minutë", diff --git a/locales/jquery.timeago.sr.js b/locales/jquery.timeago.sr.js index bd1efe79..7684f842 100644 --- a/locales/jquery.timeago.sr.js +++ b/locales/jquery.timeago.sr.js @@ -20,7 +20,7 @@ } }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["sr"] = { prefixAgo: "пре", prefixFromNow: "за", suffixAgo: null, diff --git a/locales/jquery.timeago.sv.js b/locales/jquery.timeago.sv.js index caf09dbb..91ab5a6d 100644 --- a/locales/jquery.timeago.sv.js +++ b/locales/jquery.timeago.sv.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Swedish - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["sv"] = { prefixAgo: "för", prefixFromNow: "om", suffixAgo: "sedan", diff --git a/locales/jquery.timeago.th.js b/locales/jquery.timeago.th.js index 23d59d48..5bf5981b 100644 --- a/locales/jquery.timeago.th.js +++ b/locales/jquery.timeago.th.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Thai - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["th"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "ที่แล้ว", diff --git a/locales/jquery.timeago.tr-short.js b/locales/jquery.timeago.tr-short.js index ba290dd3..690f3193 100644 --- a/locales/jquery.timeago.tr-short.js +++ b/locales/jquery.timeago.tr-short.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Turkish shortened - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["tr-short"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "", diff --git a/locales/jquery.timeago.tr.js b/locales/jquery.timeago.tr.js index 8e0d2d4e..1fb897e8 100644 --- a/locales/jquery.timeago.tr.js +++ b/locales/jquery.timeago.tr.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Turkish - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["tr"] = { suffixAgo: 'önce', suffixFromNow: null, seconds: 'birkaç saniye', diff --git a/locales/jquery.timeago.uk.js b/locales/jquery.timeago.uk.js index 489963b5..f48a093b 100644 --- a/locales/jquery.timeago.uk.js +++ b/locales/jquery.timeago.uk.js @@ -22,7 +22,7 @@ } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["uk"] = { prefixAgo: null, prefixFromNow: "через", suffixAgo: "тому", diff --git a/locales/jquery.timeago.ur.js b/locales/jquery.timeago.ur.js index 9d0cd402..770c530c 100644 --- a/locales/jquery.timeago.ur.js +++ b/locales/jquery.timeago.ur.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Urdu - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["ur"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "پہلے", diff --git a/locales/jquery.timeago.uz.js b/locales/jquery.timeago.uz.js index f4ce8b33..c065045d 100755 --- a/locales/jquery.timeago.uz.js +++ b/locales/jquery.timeago.uz.js @@ -8,7 +8,7 @@ } }(function (jQuery) { //Uzbek - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["uz"] = { prefixAgo: null, prefixFromNow: "keyin", suffixAgo: "avval", diff --git a/locales/jquery.timeago.vi.js b/locales/jquery.timeago.vi.js index 1230b1e9..72f5f849 100644 --- a/locales/jquery.timeago.vi.js +++ b/locales/jquery.timeago.vi.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Vietnamese - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["vi"] = { prefixAgo: 'cách đây', prefixFromNow: null, suffixAgo: "trước", diff --git a/locales/jquery.timeago.zh-CN.js b/locales/jquery.timeago.zh-CN.js index c21a2874..3de316ba 100644 --- a/locales/jquery.timeago.zh-CN.js +++ b/locales/jquery.timeago.zh-CN.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Simplified Chinese - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["zh-CN"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "之前", diff --git a/locales/jquery.timeago.zh-TW.js b/locales/jquery.timeago.zh-TW.js index 15f56269..19ffb235 100644 --- a/locales/jquery.timeago.zh-TW.js +++ b/locales/jquery.timeago.zh-TW.js @@ -8,7 +8,7 @@ } }(function (jQuery) { // Traditional Chinese, zh-tw - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings["zh-TW"] = { prefixAgo: null, prefixFromNow: null, suffixAgo: "之前", diff --git a/test/index.html b/test/index.html index 17d15dd9..813c8cc0 100644 --- a/test/index.html +++ b/test/index.html @@ -251,6 +251,14 @@

Do Not Allow Past

  • +

    Lang

    + + +

    Disposal

    @@ -286,10 +294,15 @@

    Disposal

    $.timeago.settings.allowFuture = true; prepareDynamicDates(); + loadStrings(); $("abbr.timeago").not("abbr.cutoff").timeago(); $("time.timeago").timeago(); + loadLang(); + $("abbr.lang").timeago(); + unloadLang(); + loadCutoffSetting(); $("abbr.cutoff").timeago(); unloadCutoffSetting(); @@ -341,6 +354,9 @@

    Disposal

    loadPolish(); $("abbr.topolish").each(toWords); + loadPlainStrings(); + $("abbr.langPlain").timeago(); + module("Valid date"); test("Text in abbr tag should be replaced", function () { @@ -738,6 +754,20 @@

    Disposal

    } }); + module("Lang"); + + test("uses lang from settings", function() { + equal($("#testLang").html(), "und"); + }) + + test("uses lang tag", function() { + equal($("#testLangTag").html(), "zxx"); + }) + + test("works with direct assigned strings", function() { + equal($("#testLangPlain").html(), "plain"); + }) + module("Disposal"); asyncTest("disposal", function() { diff --git a/test/test_helpers.js b/test/test_helpers.js index 7db41749..cf3ef63d 100644 --- a/test/test_helpers.js +++ b/test/test_helpers.js @@ -15,11 +15,70 @@ function prepareDynamicDates() { $('time.modified').attr("datetime", iso8601(new Date(document.lastModified))); } +function loadStrings() { + jQuery.timeago.settings.strings.zxx = { + suffixAgo: "", + suffixFromNow: "", + seconds: "zxx", + minute: "zxx", + minutes: "zxx", + hour: "zxx", + hours: "zxx", + day: "zxx", + days: "zxx", + month: "zxx", + months: "zxx", + year: "zxx", + years: "zxx" + } + + jQuery.timeago.settings.strings.und = { + suffixAgo: "", + suffixFromNow: "", + seconds: "und", + minute: "und", + minutes: "und", + hour: "und", + hours: "und", + day: "und", + days: "und", + month: "und", + months: "und", + year: "und", + years: "und" + } +} + +function loadPlainStrings() { + jQuery.timeago.settings.strings = { + suffixAgo: "", + suffixFromNow: "", + seconds: "plain", + minute: "plain", + minutes: "plain", + hour: "plain", + hours: "plain", + day: "plain", + days: "plain", + month: "plain", + months: "plain", + year: "plain", + years: "plain" + } +} + +function loadLang() { + jQuery.timeago.settings.lang = "und"; +} +function unloadLang() { + jQuery.timeago.settings.lang = "en"; +} + function loadNumbers() { - jQuery.timeago.settings.strings.numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; + jQuery.timeago.settings.strings.en.numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; } function unloadNumbers() { - jQuery.timeago.settings.strings.numbers = []; + jQuery.timeago.settings.strings.en.numbers = []; } function loadCutoffSetting() { @@ -36,7 +95,7 @@ function setupDisposal() { } function loadPigLatin() { - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings.en = { suffixAgo: "ago-hay", suffixFromNow: "omNow-fray", seconds: "ess-lay an-thay a-hay inute-may", @@ -67,7 +126,7 @@ function loadPolish() { } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings.en = { prefixAgo: null, prefixFromNow: "za", suffixAgo: "temu", @@ -103,7 +162,7 @@ function loadRussian() { } } - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings.en = { prefixAgo: null, prefixFromNow: "через", suffixAgo: "назад", @@ -139,13 +198,13 @@ function loadBelarusian() { } } - jQuery.timeago.settings.strings = { - prefixAgo: null, - prefixFromNow: "праз", - suffixAgo: "таму", - suffixFromNow: null, - seconds: "менш хвіліны", - minute: "хвіліну", + jQuery.timeago.settings.strings.en = { + prefixAgo: null, + prefixFromNow: "праз", + suffixAgo: "таму", + suffixFromNow: null, + seconds: "менш хвіліны", + minute: "хвіліну", minutes: function(value) { return numpf(value, "%d хвіліна", "%d хвіліны", "%d хвілін"); }, hour: "гадзіну", hours: function(value) { return numpf(value, "%d гадзіна", "%d гадзіны", "%d гадзін"); }, @@ -165,7 +224,7 @@ function resetRefreshMillis() { function loadMillis() { var millisSubstitution = function(number, millis) { return millis + " milliseconds"; }; - jQuery.timeago.settings.strings = { + jQuery.timeago.settings.strings.en = { suffixAgo: "ago", suffixFromNow: "from now", seconds: millisSubstitution, @@ -183,21 +242,21 @@ function loadMillis() { } function loadNoSpaces() { - jQuery.extend(jQuery.timeago.settings.strings, { + jQuery.extend(jQuery.timeago.settings.strings.en, { minutes: "%dminutes", wordSeparator: "" }); } function loadNullSpaces() { - jQuery.extend(jQuery.timeago.settings.strings, { + jQuery.extend(jQuery.timeago.settings.strings.en, { minutes: "%dminutes", wordSeparator: null }); } function loadYoungOldYears() { - jQuery.extend(jQuery.timeago.settings.strings, { + jQuery.extend(jQuery.timeago.settings.strings.en, { years: function(value) { return (value < 21) ? "%d young years" : "%d old years"; } }); } @@ -217,7 +276,7 @@ function loadDoNotAllowPast() { var mockDateToUse = "2010-01-01"; $.timeago.settings.allowFuture = true; $.timeago.settings.allowPast = false; - $.timeago.settings.strings.inPast = "in the past"; + $.timeago.settings.strings.en.inPast = "in the past"; enableMockedDate(mockDateToUse); }