mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: English locale with international date formats
Makes en_US the new default locale
This commit is contained in:
@@ -127,8 +127,7 @@ module JsLocaleHelper
|
||||
fallback_locale_str = LocaleSiteSetting.fallback_locale(locale_str)&.to_s
|
||||
translations = Marshal.load(Marshal.dump(translations_for(locale_str)))
|
||||
|
||||
message_formats = strip_out_message_formats!(translations[locale_str]['js'])
|
||||
message_formats.merge!(strip_out_message_formats!(translations[locale_str]['admin_js']))
|
||||
message_formats = remove_message_formats!(translations, locale)
|
||||
mf_locale, mf_filename = find_message_format_locale([locale_str], fallback_to_english: true)
|
||||
result = generate_message_format(message_formats, mf_locale, mf_filename)
|
||||
|
||||
@@ -155,7 +154,8 @@ module JsLocaleHelper
|
||||
end
|
||||
|
||||
MOMENT_LOCALE_MAPPING ||= {
|
||||
"hy" => "hy-am"
|
||||
"hy" => "hy-am",
|
||||
"en" => "en-gb"
|
||||
}
|
||||
|
||||
def self.find_moment_locale(locale_chain, timezone_names: false)
|
||||
@@ -259,18 +259,33 @@ module JsLocaleHelper
|
||||
"function(){ return #{message.inspect};}"
|
||||
end
|
||||
|
||||
def self.strip_out_message_formats!(hash, prefix = "", rval = {})
|
||||
def self.remove_message_formats!(translations, locale)
|
||||
message_formats = {}
|
||||
I18n.fallbacks[locale].map(&:to_s).each do |l|
|
||||
next unless translations.key?(l)
|
||||
|
||||
%w{js admin_js}.each do |k|
|
||||
message_formats.merge!(strip_out_message_formats!(translations[l][k]))
|
||||
end
|
||||
end
|
||||
message_formats
|
||||
end
|
||||
|
||||
def self.strip_out_message_formats!(hash, prefix = "", message_formats = {})
|
||||
if hash.is_a?(Hash)
|
||||
hash.each do |key, value|
|
||||
if value.is_a?(Hash)
|
||||
rval.merge!(strip_out_message_formats!(value, prefix + (prefix.length > 0 ? "." : "") << key, rval))
|
||||
message_formats.merge!(strip_out_message_formats!(value, join_key(prefix, key), message_formats))
|
||||
elsif key.to_s.end_with?("_MF")
|
||||
rval[prefix + (prefix.length > 0 ? "." : "") << key] = value
|
||||
message_formats[join_key(prefix, key)] = value
|
||||
hash.delete(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
rval
|
||||
message_formats
|
||||
end
|
||||
|
||||
def self.join_key(prefix, key)
|
||||
prefix.blank? ? key : "#{prefix}.#{key}"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user