Import translations by each locale, not at once (document size issue).

This commit is contained in:
Martin Edenhofer 2015-08-04 12:41:36 +02:00
parent 01298449cc
commit 3491dcf043

View file

@ -15,40 +15,42 @@ load translations from online
=end =end
def self.load def self.load
url = 'https://i18n.zammad.com/api/v1/translations' Locale.where(active: true).each {|locale|
if !UserInfo.current_user_id url = "https://i18n.zammad.com/api/v1/translations/#{locale.locale}"
UserInfo.current_user_id = 1 if !UserInfo.current_user_id
end UserInfo.current_user_id = 1
result = UserAgent.get( end
url, result = UserAgent.get(
{}, url,
{ {},
json: true, {
} json: true,
) }
fail "Can't load translations from #{url}: #{result.error}" if !result.success? )
fail "Can't load translations from #{url}: #{result.error}" if !result.success?
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
result.data.each {|translation| result.data.each {|translation|
# handle case insensitive sql # handle case insensitive sql
exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source'])
translaten = nil translaten = nil
exists.each {|item| exists.each {|item|
if item.source == translation['source'] if item.source == translation['source']
translaten = item translaten = item
end
}
if translaten
# verify if update is needed
translaten.update_attributes(translation.symbolize_keys!)
translaten.save
else
Translation.create(translation.symbolize_keys!)
end end
} }
if translaten end
}
# verify if update is needed
translaten.update_attributes(translation.symbolize_keys!)
translaten.save
else
Translation.create(translation.symbolize_keys!)
end
}
end
true true
end end