FIX: Support client locales defined in plugins

This commit is contained in:
Robin Ward 2017-11-16 16:21:53 -05:00
parent fc346d207b
commit 2974faee68
1 changed files with 12 additions and 1 deletions

View File

@ -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']