diff --git a/app-localize-behavior.html b/app-localize-behavior.html index a990747..3eb6f97 100644 --- a/app-localize-behavior.html +++ b/app-localize-behavior.html @@ -208,13 +208,14 @@ if (!key || !resources || !language) return; + var rawTranslation = proto._extractTranslation(resources, language, key); // Cache the key/value pairs for the same language, so that we don't // do extra work if we're just reusing strings across an application. - var messageKey = key + resources[language][key]; + var messageKey = key + rawTranslation; var msg = proto.__localizationCache.messages[messageKey]; if (!msg) { - msg = new IntlMessageFormat(resources[language][key], language, formats); + msg = new IntlMessageFormat(proto._extractTranslation(resources, language, key), language, formats); proto.__localizationCache.messages[messageKey] = msg; } @@ -227,6 +228,16 @@ }; }, + _extractTranslation: function (resources, language, key){ + var resource = resources[language], keyChain = key.split('.'); + + keyChain.forEach(function (currentKey) { + resource = resource[currentKey]; + }); + + return resource; + }, + __onRequestResponse: function(event) { this.resources = event.response; this.fire('app-resources-loaded'); diff --git a/test/basic-resource-tree.html b/test/basic-resource-tree.html new file mode 100644 index 0000000..b608e93 --- /dev/null +++ b/test/basic-resource-tree.html @@ -0,0 +1,320 @@ + + + +
+ +