Skip to content
Extraits de code Groupes Projets
Valider a2aff720 rédigé par Florian Staudacher's avatar Florian Staudacher
Parcourir les fichiers

clear locale on each spec run, fix indentation

parent 1f98e1c6
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -2,20 +2,21 @@
* licensed under the Affero General Public License version 3 or later. See
* the COPYRIGHT file.
*/
Diaspora.I18n = {
language: "en",
locale: {},
loadLocale: function(locale, language) {
this.locale = $.extend(this.locale, locale);
this.language = language;
rule = this.t('pluralization_rule');
if (rule === "")
rule = 'function (n) { return n == 1 ? "one" : "other" }';
eval("this.pluralizationKey = "+rule);
},
t: function(item, views) {
Diaspora.I18n = {
language: "en",
locale: {},
loadLocale: function(locale, language) {
this.locale = $.extend(this.locale, locale);
this.language = language;
rule = this.t('pluralization_rule');
if (rule === "")
rule = 'function (n) { return n == 1 ? "one" : "other" }';
eval("this.pluralizationKey = "+rule);
},
t: function(item, views) {
var items = item.split("."),
translatedMessage,
nextNamespace;
......@@ -35,5 +36,12 @@
}
return _.template(translatedMessage, views || {});
}
};
},
reset: function() {
this.locale = {};
if( arguments.length > 0 && !(_.isEmpty(arguments[0])) )
this.locale = arguments[0];
}
};
......@@ -3,69 +3,84 @@
* the COPYRIGHT file.
*/
describe("Diaspora", function() {
describe("widgets", function() {
describe("i18n", function() {
var locale = {namespace: {
message: "hey",
template: "<%= myVar %>",
otherNamespace: {
message: "hello from another namespace",
otherMessage: {
zero: "none",
one: "just one",
few: "just a few",
many: "way too many",
other: "what?"
}
}
describe("Diaspora.I18n", function() {
var locale = {namespace: {
message: "hey",
template: "<%= myVar %>",
otherNamespace: {
message: "hello from another namespace",
otherMessage: {
zero: "none",
one: "just one",
few: "just a few",
many: "way too many",
other: "what?"
}
};
}
}
};
describe("loadLocale", function() {
it("sets the class's locale variable", function() {
Diaspora.I18n.loadLocale(locale);
beforeEach(function(){
Diaspora.I18n.reset(); // run tests with clean locale
});
expect(Diaspora.I18n.locale).toEqual(locale);
});
describe("::loadLocale", function() {
it("sets the class's locale variable", function() {
Diaspora.I18n.loadLocale(locale);
it("extends the class's locale variable on multiple calls", function() {
var data = {another: 'section'},
extended = $.extend(locale, data);
expect(Diaspora.I18n.locale).toEqual(locale);
});
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.loadLocale(data);
it("extends the class's locale variable on multiple calls", function() {
var data = {another: 'section'},
extended = $.extend(locale, data);
expect(Diaspora.I18n.locale).toEqual(extended);
});
});
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.loadLocale(data);
describe("t", function() {
var translation;
beforeEach(function() { Diaspora.I18n.loadLocale(locale); });
expect(Diaspora.I18n.locale).toEqual(extended);
});
});
it("returns the specified translation", function() {
translation = Diaspora.I18n.t("namespace.message");
describe("::t", function() {
var translation;
beforeEach(function() { Diaspora.I18n.loadLocale(locale); });
expect(translation).toEqual("hey");
});
it("returns the specified translation", function() {
translation = Diaspora.I18n.t("namespace.message");
it("will go through a infinitely deep object", function() {
translation = Diaspora.I18n.t("namespace.otherNamespace.message");
expect(translation).toEqual("hey");
});
it("will go through a infinitely deep object", function() {
translation = Diaspora.I18n.t("namespace.otherNamespace.message");
expect(translation).toEqual("hello from another namespace");
});
expect(translation).toEqual("hello from another namespace");
});
it("can render a mustache template", function() {
translation = Diaspora.I18n.t("namespace.template", { myVar: "it works!" });
it("can render a mustache template", function() {
translation = Diaspora.I18n.t("namespace.template", { myVar: "it works!" });
expect(translation).toEqual("it works!");
});
expect(translation).toEqual("it works!");
});
it("returns an empty string if the translation is not found", function() {
expect(Diaspora.I18n.t("missing.locale")).toEqual("");
});
});
describe("::reset", function(){
it("clears the current locale", function() {
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.reset()
expect(Diaspora.I18n.locale).toEqual({});
});
it("returns an empty string if the translation is not found", function() {
expect(Diaspora.I18n.t("missing.locale")).toEqual("");
});
});
it("sets the locale to only a specific value", function() {
var data = { some: 'value' };
Diaspora.I18n.loadLocale(locale);
Diaspora.I18n.reset(data);
expect(Diaspora.I18n.locale).toEqual(data);
});
});
});
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter