-
-
Save gr2m/215042 to your computer and use it in GitHub Desktop.
updated karmi's gist with support for empty brackets, like "Users"[]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add your own tasks in files placed in lib/tasks ending in .rake, | |
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | |
require(File.join(File.dirname(__FILE__), 'config', 'boot')) | |
require 'rake' | |
require 'rake/testtask' | |
require 'rake/rdoctask' | |
require 'tasks/rails' | |
require 'fileutils' | |
namespace :localize do | |
desc "Extract all texts prepared to be translated from Ruby source" | |
task :extract do | |
count, keys, out = 0, [], "# Localization dictionary for the 'Gibberish' plugin (#{RAILS_ROOT.split('/').last})\n\n" | |
Dir["#{RAILS_ROOT}/app/**/*"].sort.each do |path| | |
unless ( matches = File.new(path).read.scan(/['"]([^'"\n]*)['"]\[\:?([a-z1-9\_]*)\]/) ).empty? | |
print "." | |
out << "# -- #{path.gsub(/#{RAILS_ROOT}/,'')}:\n" | |
matches.each do |m| | |
out << "#{m[1].blank? ? m[0].downcase : m[1]}: #{m[0]}\n" unless keys.include? m[1] | |
keys << m[1] | |
end | |
out << "\n" | |
count +=1 | |
end if FileTest.file? path | |
end | |
FileUtils.mkdir_p File.join(RAILS_ROOT, 'lang') # Ensure we have lang dir | |
File.open( File.join(RAILS_ROOT, 'lang', 'new_language.yml'), "w") { |file| file << out } | |
puts "\nProcessed #{count} files and dumped YAML into #{RAILS_ROOT}/lang/new_language.yml" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment