Translations
This commit is contained in:
parent
52e5e10232
commit
e5f9dc5666
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user