mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +08:00
JsLocaleHelper should search for moment.js locale files
moment.js uses a different naming conventions for locale files. E.g. "zh-zn" instead of "zh_ZN" and "nb" instead of "nb_NO" This change allows us to use the locale files without renaming which makes future upgrades of moment.js a lot easier.
This commit is contained in:
parent
8ced8350ba
commit
89add4a4a2
|
@ -123,7 +123,16 @@ module JsLocaleHelper
|
|||
end
|
||||
|
||||
def self.moment_locale(locale_str)
|
||||
# moment.js uses a different naming scheme for locale files
|
||||
locale_str = locale_str.tr('_', '-').downcase
|
||||
filename = Rails.root + "lib/javascripts/moment_locale/#{locale_str}.js"
|
||||
|
||||
unless File.exists?(filename)
|
||||
# try the language without the territory
|
||||
locale_str = locale_str.partition('-').first
|
||||
filename = Rails.root + "lib/javascripts/moment_locale/#{locale_str}.js"
|
||||
end
|
||||
|
||||
if File.exists?(filename)
|
||||
File.read(filename) << "\n"
|
||||
end || ""
|
||||
|
|
|
@ -173,6 +173,16 @@ describe JsLocaleHelper do
|
|||
ctx.load(Rails.root + 'app/assets/javascripts/locales/i18n.js')
|
||||
ctx.eval(js)
|
||||
end
|
||||
|
||||
it "finds moment.js locale file for #{locale[:value]}" do
|
||||
content = JsLocaleHelper.moment_locale(locale[:value])
|
||||
|
||||
if (locale[:value] == 'en')
|
||||
expect(content).to eq('')
|
||||
else
|
||||
expect(content).to_not eq('')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user