Skip to content

Commit

Permalink
Accept the scope as an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed May 14, 2014
1 parent 6b7d9fe commit 0b35ddd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/javascripts/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@
, translations
;

// Deal with the scope as an array.
if (scope.constructor === Array) {
scope = scope.join(this.defaultSeparator);
}

// Deal with the scope option provided through the second argument.
//
// I18n.t('hello', {scope: 'greetings'});
Expand Down
8 changes: 8 additions & 0 deletions spec/js/translate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,12 @@ describe("Translate", function(){
var options = {scope: "greetings"};
expect(I18n.t("stranger", options)).toEqual("Hello stranger!");
});

it("accepts the scope as an array", function(){
expect(I18n.t(["greetings", "stranger"])).toEqual("Hello stranger!");
});

it("accepts the scope as an array using a base scope", function(){
expect(I18n.t(["stranger"], {scope: "greetings"})).toEqual("Hello stranger!");
});
});

0 comments on commit 0b35ddd

Please sign in to comment.