From c961788a5b8b49bb1b84fd3c798169d8f1119d29 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 19 Jun 2017 23:35:34 -0400 Subject: [PATCH] Fix translation for imagery with a '.' in the id (closes #4112) --- modules/renderer/background_source.js | 6 ++++-- modules/ui/attribution.js | 3 ++- modules/util/locale.js | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/renderer/background_source.js b/modules/renderer/background_source.js index a06a52f64..38252f1ff 100644 --- a/modules/renderer/background_source.js +++ b/modules/renderer/background_source.js @@ -31,12 +31,14 @@ export function rendererBackgroundSource(data) { source.name = function() { - return t('imagery.' + source.id + '.name', { default: name }); + var id_safe = source.id.replace('.', ''); + return t('imagery.' + id_safe + '.name', { default: name }); }; source.description = function() { - return t('imagery.' + source.id + '.description', { default: description }); + var id_safe = source.id.replace('.', ''); + return t('imagery.' + id_safe + '.description', { default: description }); }; diff --git a/modules/ui/attribution.js b/modules/ui/attribution.js index 6edcb1f33..ec0ac468e 100644 --- a/modules/ui/attribution.js +++ b/modules/ui/attribution.js @@ -44,7 +44,8 @@ export function uiAttribution(context) { } - var terms_text = t('imagery.' + d.id + '.attribution.text', + var id_safe = d.id.replace('.', ''); + var terms_text = t('imagery.' + id_safe + '.attribution.text', { default: d.terms_text || d.id || d.name() } ); diff --git a/modules/util/locale.js b/modules/util/locale.js index c8eef85d1..4081c39b0 100644 --- a/modules/util/locale.js +++ b/modules/util/locale.js @@ -25,7 +25,11 @@ export function addTranslation(id, value) { export function t(s, o, loc) { loc = loc || currentLocale; - var path = s.split('.').reverse(); + var path = s + .split('.') + .map(function(s) { return s.replace('', '.'); }) + .reverse(); + var rep = translations[loc]; while (rep !== undefined && path.length) rep = rep[path.pop()];