From 2bfc7323a77c7083b404f1f41d2f71095bd17fb9 Mon Sep 17 00:00:00 2001 From: Nico0084 Date: Tue, 24 Oct 2017 19:28:22 +0200 Subject: [PATCH 1/2] Add namespace multi level on translation ressources --- app-localize-behavior.html | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app-localize-behavior.html b/app-localize-behavior.html index cf4dd21..d91f6ff 100644 --- a/app-localize-behavior.html +++ b/app-localize-behavior.html @@ -160,6 +160,11 @@ * this.resources = { * 'en': { 'greeting': 'Hello!' }, 'fr' : { 'greeting': 'Bonjour!' } * } + * With namespace multi level : + this.resources = { + * 'en': { 'login': {'greeting': 'Hello!' }}, 'fr' : { 'login': {'greeting': 'Bonjour!' }} + * } + * use with ":" separator eg : localize('login:greeting') */ resources: { type: Object @@ -264,7 +269,16 @@ // 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 translatedValue = resources[language][key]; + var subKey = key.split(":"); + if (subKey.length > 1) { + // use namesSpace multi level + var translatedValue = resources[language][subKey[0]]; + for (var i=1; i Date: Wed, 25 Oct 2017 00:25:30 +0200 Subject: [PATCH 2/2] handle undefined key --- app-localize-behavior.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app-localize-behavior.html b/app-localize-behavior.html index d91f6ff..6ff5eb3 100644 --- a/app-localize-behavior.html +++ b/app-localize-behavior.html @@ -274,7 +274,11 @@ // use namesSpace multi level var translatedValue = resources[language][subKey[0]]; for (var i=1; i