From b3ab0e57535492c3c63af08c70967bc00a00c38a Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 19 Feb 2019 16:07:19 +0100 Subject: [PATCH] FIX: moment_js locale files for zh_CN and zh_TW were not found moment_js uses a different format for locale names in plugins and files in core. Follow-up to 4799cf281131e1bf34fcb6aad49b00769cff469e --- lib/js_locale_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/js_locale_helper.rb b/lib/js_locale_helper.rb index aaefc703db5..bff6391db27 100644 --- a/lib/js_locale_helper.rb +++ b/lib/js_locale_helper.rb @@ -164,9 +164,9 @@ module JsLocaleHelper def self.find_moment_locale(locale_chain) path = "#{Rails.root}/vendor/assets/javascripts/moment-locale" - find_locale(locale_chain, path, :moment_js, fallback_to_english: false) do + find_locale(locale_chain, path, :moment_js, fallback_to_english: false) do |locale| # moment.js uses a different naming scheme for locale files - locale_chain.map { |l| l.tr('_', '-').downcase } + locale.tr('_', '-').downcase end end @@ -180,16 +180,18 @@ module JsLocaleHelper plugin_locale = DiscoursePluginRegistry.locales[locale] return plugin_locale[type] if plugin_locale&.has_key?(type) + locale = yield(locale) if block_given? filename = File.join(path, "#{locale}.js") return [locale, filename] if File.exist?(filename) end - locale_chain = yield if block_given? + locale_chain.map! { |locale| yield(locale) } if block_given? # try again, but this time only with the language itself locale_chain = locale_chain.map { |l| l.split(/[-_]/)[0] } .uniq.reject { |l| locale_chain.include?(l) } - unless locale_chain.empty? + + if locale_chain.any? locale_data = find_locale(locale_chain, path, type, fallback_to_english: false) return locale_data if locale_data end