Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rake task will now populate translations from entire project director…

…y .. but you can override.
  • Loading branch information...
commit cb8457cb9ef44b7b79af6b4f901925838c63761b 1 parent a1ccc50
Shane Mingins authored
Showing with 6 additions and 5 deletions.
  1. +3 −3 lib/i18n_util.rb
  2. +3 −2 tasks/i18n.rake
View
6 lib/i18n_util.rb
@@ -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 = {}
@@ -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
View
5 tasks/i18n.rake
@@ -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.'
Please sign in to comment.
Something went wrong with that request. Please try again.