diff --git a/bundles/ng2-translate.js b/bundles/ng2-translate.js index 1857182d..eb7bd46b 100644 --- a/bundles/ng2-translate.js +++ b/bundles/ng2-translate.js @@ -385,7 +385,7 @@ System.registerDynamic("src/translate.parser", [], true, function($__require, ex key = ''; do { key += keys.shift(); - if (target[key]) { + if (target[key] && (typeof target[key] === 'object' || !keys.length)) { target = target[key]; key = ''; } else if (!keys.length) { diff --git a/src/translate.parser.ts b/src/translate.parser.ts index 08ba1da1..21612db8 100644 --- a/src/translate.parser.ts +++ b/src/translate.parser.ts @@ -32,7 +32,7 @@ export class Parser { key = ''; do { key += keys.shift(); - if (target[key]) { + if (target[key] && (typeof target[key] === 'object' || !keys.length)) { target = target[key]; key = ''; } else if (!keys.length) { diff --git a/tests/translate.parser.spec.ts b/tests/translate.parser.spec.ts index b848f362..3fc35986 100644 --- a/tests/translate.parser.spec.ts +++ b/tests/translate.parser.spec.ts @@ -33,6 +33,10 @@ export function main() { expect(parser.getValue({key1: {'key2.key3': "value3"}}, 'key1.key2.key3')).toEqual("value3"); expect(parser.getValue({'key1.key2.key3': "value3"}, 'key1.key2.key3')).toEqual("value3"); expect(parser.getValue({'key1.key2': {key3: "value3"}}, 'key1.key2.keyWrong')).not.toBeDefined(); + expect(parser.getValue({ + 'key1': "value1", + 'key1.key2' : "value2" + }, 'key1.key2')).toEqual("value2"); }); });