Browse Source

Translations

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

7
config/initializers/i18n.rb

@ -1,10 +1,12 @@
require 'i18n/backend/active_record'
require 'yaml'
if Rails.env.test?
class DevTranslation < Translation
self.table_name = 'translations'
establish_connection :development
end
end
module I18n
class MissingTranslationExceptionHandler < ExceptionHandler
@ -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

11
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

Loading…
Cancel
Save