clear locale on each spec run, fix indentation
This commit is contained in:
parent
1f98e1c639
commit
a2aff720a2
2 changed files with 86 additions and 63 deletions
|
|
@ -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);
|
||||
},
|
||||
Diaspora.I18n = {
|
||||
language: "en",
|
||||
locale: {},
|
||||
|
||||
t: function(item, views) {
|
||||
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");
|
||||
});
|
||||
|
||||
expect(translation).toEqual("hello from another namespace");
|
||||
});
|
||||
it("will go through a infinitely deep object", function() {
|
||||
translation = Diaspora.I18n.t("namespace.otherNamespace.message");
|
||||
|
||||
it("can render a mustache template", function() {
|
||||
translation = Diaspora.I18n.t("namespace.template", { myVar: "it works!" });
|
||||
expect(translation).toEqual("hello from another namespace");
|
||||
});
|
||||
|
||||
expect(translation).toEqual("it works!");
|
||||
});
|
||||
it("can render a mustache template", function() {
|
||||
translation = Diaspora.I18n.t("namespace.template", { myVar: "it works!" });
|
||||
|
||||
it("returns an empty string if the translation is not found", function() {
|
||||
expect(Diaspora.I18n.t("missing.locale")).toEqual("");
|
||||
});
|
||||
});
|
||||
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("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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue