Skip to content

Commit

Permalink
Merge pull request #235 from TrigenSoftware/master
Browse files Browse the repository at this point in the history
objectNotation fix, again
  • Loading branch information
mashpie authored Jun 21, 2016
2 parents fcc11aa + 9222a86 commit 95d5db7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 4 additions & 4 deletions i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,8 @@ module.exports = (function() {
if (!locales[locale]) return Function.prototype;

// Handle object lookup notation
var indexOfDot = objectNotation && singular.indexOf(objectNotation);
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length)) {
var indexOfDot = objectNotation && singular.lastIndexOf(objectNotation);
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 @@ -991,8 +991,8 @@ module.exports = (function() {
if (!locales[locale]) return Function.prototype;

// Handle object lookup notation
var indexOfDot = objectNotation && singular.indexOf(objectNotation);
if (objectNotation && (0 < indexOfDot && indexOfDot < singular.length)) {
var indexOfDot = objectNotation && singular.lastIndexOf(objectNotation);
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
6 changes: 5 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"one": "plural",
"other": "plurals"
}
},
"path": {
"sub": "nested.path.sub"
}
},
"There is one monkey in the %%s": {
Expand Down Expand Up @@ -109,5 +112,6 @@
"ordered arguments with numbers": "%2$d then %1$s then %3$.2f",
"repeated argument": "%1$s, %1$s, %1$s",
". is first character": "Dot is first character",
"last character is .": "last character is Dot"
"last character is .": "last character is Dot",
"few sentences. with .": "few sentences with Dot"
}
7 changes: 7 additions & 0 deletions test/i18n.objectnotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ 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');
should.equal(__('few sentences. with .'), 'few sentences with 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 95d5db7

Please sign in to comment.