Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDan Hansen <mokker1234@gmail.com>2011-10-26 05:31:58 +0400
committerDan Hansen <mokker1234@gmail.com>2011-10-26 06:58:37 +0400
commit091db3fd66388b08455fb1c091dfb11ea7d76f37 (patch)
tree0703158fdb8a33f8be15734a09e2e3d11a5a89a2 /spec
parent1a521a792a31f3b955b9e7d7f4ffb85734156f7b (diff)
js i18n now accepts a count
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/widgets/i18n-spec.js95
1 files changed, 73 insertions, 22 deletions
diff --git a/spec/javascripts/widgets/i18n-spec.js b/spec/javascripts/widgets/i18n-spec.js
index a28e0e219..d264c9544 100644
--- a/spec/javascripts/widgets/i18n-spec.js
+++ b/spec/javascripts/widgets/i18n-spec.js
@@ -6,40 +6,91 @@
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("loadLocale", function() {
it("sets the class's locale variable", function() {
- Diaspora.I18n.loadLocale({sup: "hi"});
- expect(Diaspora.I18n.locale).toEqual({sup: "hi"});
+ Diaspora.I18n.loadLocale(locale);
+
+ expect(Diaspora.I18n.locale).toEqual(locale);
});
});
+
describe("t", function() {
+ var translation;
+ beforeEach(function() { Diaspora.I18n.loadLocale(locale); });
+
it("returns the specified translation", function() {
- Diaspora.I18n.loadLocale({yo: "sup"}, "en");
- var translation = Diaspora.I18n.t("yo");
- expect(translation).toEqual("sup");
+ translation = Diaspora.I18n.t("namespace.message");
+
+ expect(translation).toEqual("hey");
});
+
it("will go through a infinitely deep object", function() {
- Diaspora.I18n.loadLocale({
- yo: {
- hi: {
- sup: {
- test: "test"
- }
- }
- },
- more: {
- another: "i hope this spec is green"
- }
- });
- expect(Diaspora.I18n.t("yo.hi.sup.test")).toEqual("test");
- expect(Diaspora.I18n.t("more.another")).toEqual("i hope this spec is green");
+ translation = Diaspora.I18n.t("namespace.otherNamespace.message");
+
+ expect(translation).toEqual("hello from another namespace");
});
+
it("can render a mustache template", function() {
- Diaspora.I18n.loadLocale({yo: "{{yo}}"}, "en");
- expect(Diaspora.I18n.t("yo", {yo: "it works!"})).toEqual("it works!");
+ translation = Diaspora.I18n.t("namespace.template", { myVar: "it works!" });
+
+ expect(translation).toEqual("it works!");
});
+
it("returns an empty string if the translation is not found", function() {
- expect(Diaspora.I18n.t("thisstringdoesnotexist")).toEqual("");
+ expect(Diaspora.I18n.t("missing.locale")).toEqual("");
+ });
+
+ describe("count", function() {
+ function translateWith(count) {
+ translation = Diaspora.I18n.t("namespace.otherNamespace.otherMessage", {
+ count: count
+ })
+ }
+
+ it("returns the 'zero' namespace if the count is zero", function() {
+ translateWith(0);
+
+ expect(translation).toEqual("none");
+ });
+
+ it("returns the 'one' namespace if the count is one", function() {
+ translateWith(1);
+
+ expect(translation).toEqual("just one");
+ });
+
+ it("returns the 'few' namespace if the count is 2 or 3", function() {
+ translateWith(2);
+
+ expect(translation).toEqual("just a few");
+
+ translateWith(3);
+
+ expect(translation).toEqual("just a few");
+ });
+
+ it("returns the 'many' namespace for any number greater than 3", function() {
+ translateWith(50);
+
+ expect(translation).toEqual("way too many");
+ });
});
});
});