trabajo-afectivo/app/models/locale.rb

41 lines
887 B
Ruby
Raw Normal View History

2015-04-27 06:20:52 +00:00
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class Locale < ApplicationModel
def self.to_sync
locales = Locale.where(active: true)
if Rails.env.test?
locales = Locale.where(active: true, locale: ['en-us', 'de-de'])
end
locales
end
2015-04-27 06:20:52 +00:00
def self.load
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 06:20:52 +00:00
}
)
2015-04-27 11:57:36 +00:00
2015-07-16 13:12:33 +00:00
fail "Can't load locales from #{url}" if !result
fail "Can't load locales from #{url}: #{result.error}" if !result.success?
2015-04-27 11:57:36 +00:00
2015-04-28 21:08:39 +00:00
ActiveRecord::Base.transaction do
result.data.each {|locale|
exists = Locale.find_by(locale: locale['locale'])
2015-04-28 21:08:39 +00:00
if exists
exists.update(locale.symbolize_keys!)
else
Locale.create(locale.symbolize_keys!)
end
}
end
2015-04-27 06:20:52 +00:00
true
end
end