Skip to content

Commit

Permalink
Merge 8d368a8 into 7073812
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Feb 20, 2016
2 parents 7073812 + 8d368a8 commit bbcfa97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ function localeAccessor(locale, singular, allowDelayedTraversal) {

// Handle object lookup notation
var indexOfDot = objectNotation && singular.indexOf(objectNotation);
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length)) {
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length - 1)) {
// If delayed traversal wasn't specifically forbidden, it is allowed.
if (typeof allowDelayedTraversal == "undefined") allowDelayedTraversal = true;
// The accessor we're trying to find and which we want to return.
Expand Down Expand Up @@ -750,7 +750,7 @@ function localeMutator(locale, singular, allowBranching) {

// Handle object lookup notation
var indexOfDot = objectNotation && singular.indexOf(objectNotation);
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length)) {
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length - 1)) {
// If branching wasn't specifically allowed, disable it.
if (typeof allowBranching == "undefined") allowBranching = false;
// This will become the function we want to return.
Expand Down
4 changes: 3 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@
},
"ordered arguments": "%2$s then %1$s",
"ordered arguments with numbers": "%2$d then %1$s then %3$.2f",
"repeated argument": "%1$s, %1$s, %1$s"
"repeated argument": "%1$s, %1$s, %1$s",
". is first character": "Dot is first character",
"last character is .": "last character is Dot"
}
6 changes: 6 additions & 0 deletions test/i18n.objectnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ describe('Object Notation', function () {
should.throws(__('greeting.placeholder.loud', 'Marcus'));
});

it('should return en translations as expected, when dot is first or last character', function () {
i18n.setLocale('en');
should.equal(__('. is first character'), 'Dot is first character');
should.equal(__('last character is .'), 'last character is Dot');
});

it('should provide proper pluralization support, using object traversal notation', function () {
i18n.setLocale('en');
var singular = __n({singular: "cat", plural: "cat", locale: "de"}, 1),
Expand Down

0 comments on commit bbcfa97

Please sign in to comment.