2015-04-27 06:20:52 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class Locale < ApplicationModel
|
|
|
|
|
|
|
|
def self.load
|
2015-04-27 11:47:48 +00:00
|
|
|
url = 'https://i18n.zammad.com/api/v1/locales'
|
2015-04-27 06:20:52 +00:00
|
|
|
|
|
|
|
result = UserAgent.get(
|
|
|
|
url,
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
:json => true,
|
|
|
|
}
|
|
|
|
)
|
2015-04-27 11:57:36 +00:00
|
|
|
|
|
|
|
raise "Can't load locales from #{url}: #{result.error}" if !result.success?
|
|
|
|
|
2015-04-27 06:20:52 +00:00
|
|
|
result.data.each {|locale|
|
|
|
|
puts locale.inspect
|
|
|
|
exists = Locale.where(:locale => locale['locale']).first
|
|
|
|
if exists
|
|
|
|
exists.update(locale.symbolize_keys!)
|
|
|
|
else
|
|
|
|
Locale.create(locale.symbolize_keys!)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|