Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple locales concurrent #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions jquery.timeago.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -84,7 +87,7 @@
}

if (!this.settings.allowPast && distanceMillis >= 0) {
return this.settings.strings.inPast;
return $l.inPast;
}

var seconds = Math.abs(distanceMillis) / 1000;
Expand Down Expand Up @@ -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'));
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.af.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Afrikaans
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["af"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "gelede",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.am.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Amharic
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["am"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "በፊት",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.ar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.az-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Azerbaijani shortened
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["az-short"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.az.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Azerbaijani
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["az"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: 'əvvəl',
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.be.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}
}

jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["be"] = {
prefixAgo: null,
prefixFromNow: "праз",
suffixAgo: "таму",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.bg.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Bulgarian
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["bg"] = {
prefixAgo: "преди",
prefixFromNow: "след",
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.bs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
};

jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["bs"] = {
prefixAgo: "prije",
prefixFromNow: "za",
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Catalan
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["ca"] = {
prefixAgo: "fa",
prefixFromNow: "d'aquí",
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Welsh
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["cy"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "yn ôl",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.da.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Danish
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["da"] = {
prefixAgo: "for",
prefixFromNow: "om",
suffixAgo: "siden",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.de-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// German shortened
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["de-short"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.de.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// German
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["de"] = {
prefixAgo: "vor",
prefixFromNow: "in",
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.dv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "ކުރިން",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.el.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Greek
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["el"] = {
prefixAgo: "πριν",
prefixFromNow: "σε",
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.en-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// English shortened
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["en-short"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.en.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// English (Template)
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["en"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "ago",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.eo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// English (Template) -> Esperanto
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["eo"] = {
prefixAgo: "antaŭ",
prefixFromNow: null,
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.es-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Spanish shortened
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["es-short"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Spanish
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["es"] = {
prefixAgo: "hace",
prefixFromNow: "dentro de",
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.et.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Estonian
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["et"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "tagasi",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.eu.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
factory(jQuery);
}
}(function (jQuery) {
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["eu"] = {
prefixAgo: "duela",
prefixFromNow: "hemendik",
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.fa-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// persian shortened
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["fa-short"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.fa.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Persian
// Use DIR attribute for RTL text in Persian Language for ABBR tag .
// By [email protected]
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["fa"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "پیش",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Finnish
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["fi"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "sitten",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.fr-short.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Galician
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["gl"] = {
prefixAgo: "hai",
prefixFromNow: "dentro de",
suffixAgo: "",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.he.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Hebrew
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["he"] = {
prefixAgo: "לפני",
prefixFromNow: "עוד",
seconds: "פחות מדקה",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.hr.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
};

jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["hr"] = {
prefixAgo: "prije",
prefixFromNow: "za",
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.hu.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Hungarian
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["hu"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: null,
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.hy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Armenian
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["hy"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "առաջ",
Expand Down
2 changes: 1 addition & 1 deletion locales/jquery.timeago.id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
}(function (jQuery) {
// Indonesian
jQuery.timeago.settings.strings = {
jQuery.timeago.settings.strings["id"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "yang lalu",
Expand Down
Loading