Retrospring/config/late_initializers/flags.rb

30 lines
827 B
Ruby
Raw Normal View History

2015-06-09 10:57:32 -07:00
APP_LOCALES = {}
# locale_str: [language, country code]
# generate list
I18n.with_locale("") do
locale_map = YAML.load(File.open Rails.root.join("config/hl_to_cc.yml"))
flag_map = YAML.load(File.open Rails.root.join("config/flags.yml"))
Dir.glob(Rails.root.join("config/locales/*.yml")).each do |locale|
l = locale.split("/").last.split(".").first.downcase
if APP_LOCALES[l].nil?
2015-06-21 00:03:29 -07:00
cc = l.split '-'
if cc.length == 1
cc = cc.first.split '_'
end
cc = cc.last
2015-06-09 10:57:32 -07:00
2015-06-09 11:05:33 -07:00
if flag_map.index(cc).nil? and not locale_map[cc].nil?
2015-06-09 10:57:32 -07:00
cc = locale_map[cc]
end
2015-06-09 11:05:33 -07:00
begin
lang = I18n.translate("#{l}.language")
2015-06-21 00:03:29 -07:00
lang = cc if lang.index "translation missing"
2015-06-09 11:05:33 -07:00
APP_LOCALES[l] = [lang, cc]
rescue
2015-06-21 00:03:29 -07:00
APP_LOCALES[l] = [cc, cc]
2015-06-09 10:57:32 -07:00
end
end
end
end