From 3491dcf043ece266fbc6425d228357e67a6b54a5 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 4 Aug 2015 12:41:36 +0200 Subject: [PATCH] Import translations by each locale, not at once (document size issue). --- app/models/translation.rb | 62 ++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/app/models/translation.rb b/app/models/translation.rb index dbd4dce86..2f4d9cb58 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -15,40 +15,42 @@ load translations from online =end def self.load - url = 'https://i18n.zammad.com/api/v1/translations' - if !UserInfo.current_user_id - UserInfo.current_user_id = 1 - end - result = UserAgent.get( - url, - {}, - { - json: true, - } - ) - fail "Can't load translations from #{url}: #{result.error}" if !result.success? + Locale.where(active: true).each {|locale| + url = "https://i18n.zammad.com/api/v1/translations/#{locale.locale}" + if !UserInfo.current_user_id + UserInfo.current_user_id = 1 + end + result = UserAgent.get( + url, + {}, + { + json: true, + } + ) + fail "Can't load translations from #{url}: #{result.error}" if !result.success? - ActiveRecord::Base.transaction do - result.data.each {|translation| + ActiveRecord::Base.transaction do + result.data.each {|translation| - # handle case insensitive sql - exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) - translaten = nil - exists.each {|item| - if item.source == translation['source'] - translaten = item + # handle case insensitive sql + exists = Translation.where(locale: translation['locale'], format: translation['format'], source: translation['source']) + translaten = nil + exists.each {|item| + if item.source == translation['source'] + 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 } - if translaten - - # verify if update is needed - translaten.update_attributes(translation.symbolize_keys!) - translaten.save - else - Translation.create(translation.symbolize_keys!) - end - } - end + end + } true end