Browse Source

Translations

development
Godwin 11 years ago
parent
commit
e5f9dc5666
  1. 9
      config/initializers/i18n.rb
  2. 11
      lib/tasks/translations.rake

9
config/initializers/i18n.rb

@ -1,9 +1,11 @@
require 'i18n/backend/active_record' require 'i18n/backend/active_record'
require 'yaml' require 'yaml'
class DevTranslation < Translation if Rails.env.test?
class DevTranslation < Translation
self.table_name = 'translations' self.table_name = 'translations'
establish_connection :development establish_connection :development
end
end end
module I18n module I18n
@ -101,7 +103,8 @@ module I18n
YAML.load_file(@@translations_file) || {} YAML.load_file(@@translations_file) || {}
rescue Exception => e rescue Exception => e
# sometimes concurrency issues cause an exception during testing # sometimes concurrency issues cause an exception during testing
puts e puts e.class
x
sleep(1/2.0) sleep(1/2.0)
get_translation_info() get_translation_info()
end end
@ -174,7 +177,7 @@ module I18n
unless translations[key.to_s].has_key?('data') unless translations[key.to_s].has_key?('data')
translations[key.to_s]['data'] = Array.new 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| 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) unless translations[key.to_s]['languages'].include?(t.locale.to_s)
translations[key.to_s]['languages'] << t.locale.to_s translations[key.to_s]['languages'] << t.locale.to_s
end end

11
lib/tasks/translations.rake

@ -7,7 +7,16 @@ namespace :translations do
translations = YAML.load(File.read('config/locales/.translations.yml')) || Hash.new translations = YAML.load(File.read('config/locales/.translations.yml')) || Hash.new
translations.each { |k,t| translations.each { |k,t|
if t['data'] 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
} }
end end

Loading…
Cancel
Save