From 2974faee68616411d887ca31a604e090932f0553 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 16 Nov 2017 16:21:53 -0500 Subject: [PATCH] FIX: Support client locales defined in plugins --- lib/js_locale_helper.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 7444e393874..172c4c0ac57 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -38,7 +38,18 @@ module JsLocaleHelper locale_str = locale.to_s # load default translations - translations = YAML.load_file("#{Rails.root}/config/locales/client.#{locale_str}.yml") + yml_file = "#{Rails.root}/config/locales/client.#{locale_str}.yml" + if File.exist?(yml_file) + translations = YAML.load_file(yml_file) + else + # If we can't find a base file in Discourse, it might only exist in a plugin + # so let's start with a basic object we can merge into + translations = { + locale_str => { + 'js' => {} + } + } + end # merge translations (plugin translations overwrite default translations) translations[locale_str]['js'].deep_merge!(plugin_translations(locale_str)['js']) if translations[locale_str] && plugin_translations(locale_str) && plugin_translations(locale_str)['js']