lib/missing_t.rb in missing_t-0.3.0 vs lib/missing_t.rb in missing_t-0.3.1

- old
+ new

@@ -50,11 +50,11 @@ end class MissingT - VERSION = "0.3.0" + VERSION = "0.3.1" include Helpers extend Forwardable def_delegators :@translations, :[] @@ -79,11 +79,11 @@ puts opts exit end opts.on_tail("--version", "Show version") do - puts "0.1.2" + puts VERSION exit end opts.parse!(args) end @@ -106,23 +106,10 @@ add_translations(translations_in_file(file)) end end end - def hashify(strings) - h = Hash.new - strings.map { |s| s.split('.') }. - each do |segmented_string| - root = h - segmented_string.each do |segment| - root[segment] ||= {} - root = root[segment] - end - end - h - end - def translations_in_file(yaml_file) open(yaml_file) { |f| YAML.load(f.read) } end def files_with_i18n_queries @@ -150,18 +137,16 @@ file_content.scan(i18n_query_pattern).map { |match| match.first.gsub(/['"\s]/, '') }. concat(file_content.scan(i18n_query_no_parens_pattern).map { |match| match[1].gsub(/['"\s]/, '') }) end def collect_translation_queries - queries = {} - files_with_i18n_queries.each do |file| + files_with_i18n_queries.each_with_object({}) do |file, queries| queries_in_file = extract_i18n_queries(file) - unless queries_in_file.empty? + if queries_in_file.any? queries[file] = queries_in_file end end - queries #TODO: remove duplicate queries across files end def has_translation?(lang, query) t = translations @@ -170,24 +155,21 @@ t = t[segment] end true end - def get_missing_translations(queries, lang=nil) - missing = {} - languages = lang.nil? ? translations.keys : [lang] - languages.each do |l| - get_missing_translations_for_lang(queries, l).each do |file, qs| + def get_missing_translations(queries, languages) + languages.each_with_object({}) do |lang, missing| + get_missing_translations_for_lang(queries, lang).each do |file, queries| missing[file] ||= [] - missing[file].concat(qs).uniq! + missing[file].concat(queries).uniq! end end - missing end def find_missing_translations(lang=nil) collect_translations - get_missing_translations(collect_translation_queries, lang) + get_missing_translations(collect_translation_queries, lang ? [lang] : translations.keys) end private def get_missing_translations_for_lang(queries, lang) queries.map do |file, queries_in_file|