diff --git a/config/initializers/i18n.rb b/config/initializers/i18n.rb index d41f185..5513cd0 100644 --- a/config/initializers/i18n.rb +++ b/config/initializers/i18n.rb @@ -1,9 +1,11 @@ require 'i18n/backend/active_record' require 'yaml' -class DevTranslation < Translation - self.table_name = 'translations' - establish_connection :development +if Rails.env.test? + class DevTranslation < Translation + self.table_name = 'translations' + establish_connection :development + end end module I18n @@ -101,7 +103,8 @@ module I18n YAML.load_file(@@translations_file) || {} rescue Exception => e # sometimes concurrency issues cause an exception during testing - puts e + puts e.class + x sleep(1/2.0) get_translation_info() end @@ -174,7 +177,7 @@ module I18n unless translations[key.to_s].has_key?('data') translations[key.to_s]['data'] = Array.new DevTranslation.where("key = '#{key.to_s}' OR key LIKE '#{key.to_s}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%'").each { |t| - translations[key.to_s]['data'] << t.becomes(Translation) + translations[key.to_s]['data'] << ActiveSupport::JSON.encode(t.becomes(Translation)) unless translations[key.to_s]['languages'].include?(t.locale.to_s) translations[key.to_s]['languages'] << t.locale.to_s end diff --git a/lib/tasks/translations.rake b/lib/tasks/translations.rake index 8ac0a73..991aa13 100644 --- a/lib/tasks/translations.rake +++ b/lib/tasks/translations.rake @@ -7,7 +7,16 @@ namespace :translations do translations = YAML.load(File.read('config/locales/.translations.yml')) || Hash.new translations.each { |k,t| if t['data'] - t['data'].each { |tt| tt.save } + t['data'].each { |tt| + hash = ActiveSupport::JSON.decode(tt) + translation = Translation.find(hash['id']) + if translation + #t.assign_attributes(hash) + translation.update_attributes(hash) + else + Translation.new(hash).save + end + } end } end