Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

introduced options.lang + automagic mapping for multiple language support.. #88

Open
wants to merge 1 commit into from

1 participant

@eFrane

I found myself in a situation where I needed to use multiple localization within a single page load. The solution I came up with does, despite involving a simple change in every localization file, work quite simple.

I am not sure though if I put the language detection code at the correct location. (It currently is at https://github.com/eFrane/jquery-timeago/blob/options.lang/jquery.timeago.js#L131)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 jquery.timeago.js
@@ -31,7 +31,8 @@
settings: {
refreshMillis: 60000,
allowFuture: false,
- strings: {
+ lang: "en",
+ strings: { "en": {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "ago",
@@ -49,10 +50,10 @@
years: "%d years",
wordSeparator: " ",
numbers: []
- }
+ }}
},
inWords: function(distanceMillis) {
- var $l = this.settings.strings;
+ var $l = this.settings.strings[this.settings.lang];
var prefix = $l.prefixAgo;
var suffix = $l.suffixAgo;
if (this.settings.allowFuture) {
@@ -127,6 +128,7 @@
}
function prepareData(element) {
+ $t.settings.lang = ($(element).attr('lang')) ? $(element).attr('lang') : $t.settings.lang;
element = $(element);
if (!element.data("timeago")) {
element.data("timeago", { datetime: $t.datetime(element) });
View
4 locales/jquery.timeago.de.js
@@ -1,5 +1,5 @@
// German
-jQuery.timeago.settings.strings = {
+jQuery.timeago.settings.strings["de"] = {
prefixAgo: "vor",
prefixFromNow: "in",
suffixAgo: "",
@@ -15,4 +15,4 @@ jQuery.timeago.settings.strings = {
months: "%d Monaten",
year: "etwa einem Jahr",
years: "%d Jahren"
-};
+};
View
2  locales/jquery.timeago.en.js
@@ -1,5 +1,5 @@
// English (Template)
-jQuery.timeago.settings.strings = {
+jQuery.timeago.settings.strings["en"] = {
prefixAgo: null,
prefixFromNow: null,
suffixAgo: "ago",
Something went wrong with that request. Please try again.