From 84c56e16f9f1209f4ec62c7e7f7dbb79e5180035 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 19 Feb 2019 14:42:58 +0100 Subject: [PATCH] REFACTOR: Use keyword argument for fallback_to_english flag --- app/models/translation_override.rb | 2 +- lib/i18n/locale_file_checker.rb | 2 +- lib/js_locale_helper.rb | 12 ++++++------ lib/plugin/instance.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/translation_override.rb b/app/models/translation_override.rb index 52b959ad5b7..a2eeb1b9d72 100644 --- a/app/models/translation_override.rb +++ b/app/models/translation_override.rb @@ -21,7 +21,7 @@ class TranslationOverride < ActiveRecord::Base data = { value: value } if key.end_with?('_MF') - _, filename = JsLocaleHelper.find_message_format_locale([locale], false) + _, filename = JsLocaleHelper.find_message_format_locale([locale], fallback_to_english: false) data[:compiled_js] = JsLocaleHelper.compile_message_format(filename, locale, value) end diff --git a/lib/i18n/locale_file_checker.rb b/lib/i18n/locale_file_checker.rb index b9aa206bb04..54b27d9a71f 100644 --- a/lib/i18n/locale_file_checker.rb +++ b/lib/i18n/locale_file_checker.rb @@ -112,7 +112,7 @@ class LocaleFileChecker end def check_message_format - mf_locale, mf_filename = JsLocaleHelper.find_message_format_locale([@locale], true) + mf_locale, mf_filename = JsLocaleHelper.find_message_format_locale([@locale], fallback_to_english: true) traverse_hash(@locale_yaml, []) do |keys, value| next unless keys.last.ends_with?("_MF") diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index 4e0cbc4b8d9..22fe03be3b9 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -137,7 +137,7 @@ module JsLocaleHelper message_formats = strip_out_message_formats!(translations[locale_str]['js']) message_formats.merge!(strip_out_message_formats!(translations[locale_str]['admin_js'])) - mf_locale, mf_filename = find_message_format_locale([locale_str], true) + mf_locale, mf_filename = find_message_format_locale([locale_str], fallback_to_english: true) result = generate_message_format(message_formats, mf_locale, mf_filename) translations.keys.each do |l| @@ -167,15 +167,15 @@ module JsLocaleHelper # moment.js uses a different naming scheme for locale files locale_chain = locale_chain.map { |l| l.tr('_', '-').downcase } - find_locale(locale_chain, path, :moment_js, false) + find_locale(locale_chain, path, :moment_js, fallback_to_english: false) end - def self.find_message_format_locale(locale_chain, fallback_to_english) + def self.find_message_format_locale(locale_chain, fallback_to_english:) path = "#{Rails.root}/lib/javascripts/locale" - find_locale(locale_chain, path, :message_format, fallback_to_english) + find_locale(locale_chain, path, :message_format, fallback_to_english: fallback_to_english) end - def self.find_locale(locale_chain, path, type, fallback_to_english) + def self.find_locale(locale_chain, path, type, fallback_to_english:) locale_chain.each do |locale| plugin_locale = DiscoursePluginRegistry.locales[locale] return plugin_locale[type] if plugin_locale&.has_key?(type) @@ -188,7 +188,7 @@ module JsLocaleHelper locale_chain = locale_chain.map { |l| l.split(/[-_]/)[0] } .uniq.reject { |l| locale_chain.include?(l) } unless locale_chain.empty? - locale_data = find_locale(locale_chain, path, type, false) + locale_data = find_locale(locale_chain, path, type, fallback_to_english: false) return locale_data if locale_data end diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 53552d0b479..940cc905337 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -632,7 +632,7 @@ class Plugin::Instance path = File.join(lib_locale_path, "message_format") opts[:message_format] = find_locale_file(locale_chain, path) - opts[:message_format] = JsLocaleHelper.find_message_format_locale(locale_chain, false) unless opts[:message_format] + opts[:message_format] = JsLocaleHelper.find_message_format_locale(locale_chain, fallback_to_english: false) unless opts[:message_format] path = File.join(lib_locale_path, "moment_js") opts[:moment_js] = find_locale_file(locale_chain, path)