diff --git a/i18n.js b/i18n.js index 6ae33329..67383f2a 100644 --- a/i18n.js +++ b/i18n.js @@ -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. @@ -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. diff --git a/locales/en.json b/locales/en.json index 49153fcf..7552ceae 100644 --- a/locales/en.json +++ b/locales/en.json @@ -25,6 +25,9 @@ "one": "plural", "other": "plurals" } + }, + "path": { + "sub": "nested.path.sub" } }, "There is one monkey in the %%s": { @@ -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" } \ No newline at end of file diff --git a/test/i18n.objectnotation.js b/test/i18n.objectnotation.js index 4e80405e..fcd4f21d 100644 --- a/test/i18n.objectnotation.js +++ b/test/i18n.objectnotation.js @@ -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);