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:
Gerhard Schlager
2016-02-05 21:49:03 +01:00
parent 8ced8350ba
commit 89add4a4a2
2 changed files with 19 additions and 0 deletions

View File

@@ -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 || ""