From 2eeb50dfc1f1a0fdc84d45400eb98fabd3be3ba4 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Fri, 17 Jun 2022 19:34:08 +0200 Subject: [PATCH] FIX: Extra-locale merging didn't account for fallbacks (#17128) Regressed in #17027 --- lib/js_locale_helper.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 0b5164665aa..009b75698f4 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -202,8 +202,9 @@ module JsLocaleHelper def self.output_extra_locales(bundle, locale) translations = translations_for(locale) + locales = translations.keys - translations.keys.each do |l| + locales.each do |l| translations[l].keys.each do |k| bundle_translations = translations[l].delete(k) translations[l].deep_merge!(bundle_translations) if k == bundle @@ -212,17 +213,15 @@ module JsLocaleHelper return "" if translations.blank? - <<~JS - if (!I18n.extras) { - I18n.extras = {} - } + output = +"if (!I18n.extras) { I18n.extras = {}; }" + locales.each do |l| + output << <<~JS + if (!I18n.extras["#{l}"]) { I18n.extras["#{l}"] = {}; } + Object.assign(I18n.extras["#{l}"], #{translations[l].to_json}); + JS + end - if (!I18n.extras["#{locale}"]) { - I18n.extras["#{locale}"] = {}; - } - - Object.assign(I18n.extras["#{locale}"], #{translations[locale].to_json}); - JS + output end MOMENT_LOCALE_MAPPING ||= {