Skip to content
This repository
Browse code

Rake task will now populate translations from entire project director…

…y .. but you can override.
  • Loading branch information...
commit cb8457cb9ef44b7b79af6b4f901925838c63761b 1 parent a1ccc50
authored April 14, 2009
6  lib/i18n_util.rb
@@ -59,8 +59,8 @@ def self.extract_i18n_keys(hash, parent_keys = [])
59 59
   end
60 60
 
61 61
   # Create translation records for all existing locales from translation calls with the application.  Ignores errors from tranlations that require objects.
62  
-  def self.seed_application_translations
63  
-    translated_objects.each do |object|
  62
+  def self.seed_application_translations(dir='app')
  63
+    translated_objects(dir).each do |object|
64 64
       interpolation_arguments= object.scan(/\{\{(.*?)\}\}/).flatten
65 65
       object = object[/'(.*?)'/, 1] || object[/"(.*?)"/, 1]
66 66
       options = {}
@@ -83,7 +83,7 @@ def self.translated_objects(dir='app')
83 83
     assets = []
84 84
     Dir.glob("#{dir}/*").each do |item|
85 85
       if File.directory?(item)
86  
-        assets += translated_objects(item)
  86
+        assets += translated_objects(item) unless item.ends_with?('i18n_backend_database') # ignore self
87 87
       else
88 88
         File.readlines(item).each do |l|
89 89
           assets += l.scan(/I18n.t\((.*?)\)/).flatten
5  tasks/i18n.rake
@@ -31,9 +31,10 @@ namespace :i18n do
31 31
       end
32 32
     end
33 33
 
34  
-    desc 'Populate the translation tables from translation calls within the application. This only works on basic text translations'
  34
+    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.'
35 35
     task :from_application => :environment do
36  
-      I18nUtil.seed_application_translations
  36
+      dir = ENV['DIR'] ? ENV['DIR'] : "."
  37
+      I18nUtil.seed_application_translations(dir)
37 38
     end
38 39
 
39 40
     desc 'Create translation records from all default locale translations if none exists.'

0 notes on commit cb8457c

Please sign in to comment.
Something went wrong with that request. Please try again.