Load countries
This commit is contained in:
parent
23fe484a2e
commit
ff956febee
|
@ -35,5 +35,11 @@ module Justask
|
|||
# Instead, the errors will propagate normally just like in other Active Record callbacks.
|
||||
# fix for this warning:
|
||||
config.active_record.raise_in_transactional_callbacks = true
|
||||
|
||||
config.after_initialize do
|
||||
Dir.glob Rails.root.join('config/late_initializers/*.rb') do |f|
|
||||
require f
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
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?
|
||||
cc = l.split("-").last
|
||||
|
||||
if flag_map.index(cc).nil?
|
||||
cc = locale_map[cc]
|
||||
end
|
||||
|
||||
unless flag_map.index(cc).nil?
|
||||
begin
|
||||
lang = I18n.translate("#{l}.language")
|
||||
lang = '' if lang == "translation missing: #{l}.language"
|
||||
APP_LOCALES[l] = [lang, cc]
|
||||
rescue I18n.MissingTranslationData
|
||||
APP_LOCALES[l] = ['', cc]
|
||||
rescue
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue