Skip to content

Commit

Permalink
Rake task will now populate translations from entire project director…
Browse files Browse the repository at this point in the history
…y .. but you can override.
  • Loading branch information
Shane Mingins authored and Shane Mingins committed Apr 13, 2009
1 parent a1ccc50 commit cb8457c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/i18n_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def self.extract_i18n_keys(hash, parent_keys = [])
end

# 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|
def self.seed_application_translations(dir='app')
translated_objects(dir).each do |object|
interpolation_arguments= object.scan(/\{\{(.*?)\}\}/).flatten
object = object[/'(.*?)'/, 1] || object[/"(.*?)"/, 1]
options = {}
Expand All @@ -83,7 +83,7 @@ def self.translated_objects(dir='app')
assets = []
Dir.glob("#{dir}/*").each do |item|
if File.directory?(item)
assets += translated_objects(item)
assets += translated_objects(item) unless item.ends_with?('i18n_backend_database') # ignore self
else
File.readlines(item).each do |l|
assets += l.scan(/I18n.t\((.*?)\)/).flatten
Expand Down
5 changes: 3 additions & 2 deletions tasks/i18n.rake
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ namespace :i18n do
end
end

desc 'Populate the translation tables from translation calls within the application. This only works on basic text translations'
desc 'Populate the translation tables from translation calls within the application. This only works on basic text translations. Can set DIR to override starting directory.'
task :from_application => :environment do
I18nUtil.seed_application_translations
dir = ENV['DIR'] ? ENV['DIR'] : "."
I18nUtil.seed_application_translations(dir)
end

desc 'Create translation records from all default locale translations if none exists.'
Expand Down

0 comments on commit cb8457c

Please sign in to comment.