Skip to content

Commit

Permalink
Improve seeding translations from application .. I hope. Need regexpr…
Browse files Browse the repository at this point in the history
… guru!
  • Loading branch information
Shane Mingins authored and Shane Mingins committed Mar 20, 2009
1 parent 984c890 commit e1faa3f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/i18n_util.rb
Expand Up @@ -58,17 +58,23 @@ def self.extract_i18n_keys(hash, parent_keys = [])
# Create translation records for all existing locales from translation calls with the application. Ignores errors from tranlations that require objects.
def self.seed_application_translations
translated_objects.each do |object|
interpolation_arguments= object.scan(/\{\{(.*?)\}\}/).flatten
object = object[/'(.*?)'/, 1] || object[/"(.*?)"/, 1]
options = {}
interpolation_arguments.each { |arg| options[arg.to_sym] = nil }

begin
I18n.t(object) # default locale first
I18n.t(object, options) # default locale first
locales = Locale.available_locales
locales.delete(I18n.default_locale)
# translate for other locales
locales.each do |locale|
I18n.t(object, :locale => locale)
I18n.t(object, options.merge(:locale => locale))
end
rescue Exception => e
# ignore errors
end

end
end

Expand All @@ -79,7 +85,7 @@ def self.translated_objects(dir='app')
assets += translated_objects(item)
else
File.readlines(item).each do |l|
assets += l.scan(/I18n.t\(["'](.*?)["']\)/).flatten
assets += l.scan(/I18n.t\((.*?)\)/).flatten
end
end
end
Expand Down

0 comments on commit e1faa3f

Please sign in to comment.