lib/i18n/tasks/task_helpers.rb in i18n-tasks-0.0.2 vs lib/i18n/tasks/task_helpers.rb in i18n-tasks-0.0.3

- old
+ new

@@ -1,10 +1,12 @@ require 'open3' +require 'term/ansicolor' module I18n module Tasks module TaskHelpers + include Term::ANSIColor def run_command(*args) _in, out, _err = Open3.popen3(*args) out.gets nil end @@ -15,9 +17,25 @@ end # main locale file path (for writing to) def locale_file_path(locale) "config/locales/#{locale}.yml" + end + + # find all keys in the source + def find_source_keys + @source_keys ||= begin + grep_out = run_command 'grep', '-horI', %q{\\bt(\\?\\s*['"]\\([^'"]*\\)['"]}, 'app/' + used_keys = grep_out.split("\n").map { |r| r.match(/['"](.*?)['"]/)[1] }.uniq.to_set + end + end + + def find_source_pattern_keys + find_source_keys.select { |k| k =~ /\#{.*?}/ || k.ends_with?('.') } + end + + def find_source_pattern_prefixes + find_source_pattern_keys.map { |k| k.split(/\.?#/)[0] } end # traverse hash, yielding with full key and value def traverse(path = '', hash, &block) hash.each do |k, v|