Class: I18nAdminUtils::SearchTranslation
- Inherits:
-
Object
- Object
- I18nAdminUtils::SearchTranslation
- Defined in:
- lib/i18n_admin_utils/search_translation.rb
Constant Summary collapse
- HTML_PLAIN_TEXT_REGEX =
Regex that match plain text in html
/(?<=>)(([^><])+)(?=<)/
Class Method Summary collapse
- .check_results(results) ⇒ Object
- .find_plain_text ⇒ Object
- .find_plain_text_in_file(filename) ⇒ Object
- .find_translation ⇒ Object
- .search ⇒ Object
Class Method Details
.check_results(results) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/i18n_admin_utils/search_translation.rb', line 30 def self.check_results(results) output = SearchResult.new results.each do |result| key = result[:key] I18nAdminUtils::Config.locales.each do |locale| if I18n.t(key, :locale => locale, :default => 'empty') == 'empty' copy_result = result.clone copy_result[:locale] = locale output << copy_result end end end output end |
.find_plain_text ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/i18n_admin_utils/search_translation.rb', line 45 def self.find_plain_text results = SearchResult.new dirs = I18nAdminUtils::Config.search_folders dirs.each do |dir| Dir.glob("#{dir}/**/*.*").each do |filename| results += find_plain_text_in_file(filename) end end results end |
.find_plain_text_in_file(filename) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/i18n_admin_utils/search_translation.rb', line 56 def self.find_plain_text_in_file(filename) results = SearchResult.new File.open(filename).read.scan(HTML_PLAIN_TEXT_REGEX).each do |result| results << {:key => result[0], :filename => filename} unless result[0].blank? end results end |
.find_translation ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/i18n_admin_utils/search_translation.rb', line 11 def self.find_translation results = SearchResult.new dirs = I18nAdminUtils::Config.search_folders dirs.each do |dir| Dir.glob("#{dir}/**/*.*").each do |filename| i = 1 File.open(filename).each_line do |line| line.scan(/t\(("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')\)/).each do |result| key = result[0][1...-1] results << {:key => key, :filename => filename, :line => i} end i += 1 end end end results end |
.search ⇒ Object
6 7 8 9 |
# File 'lib/i18n_admin_utils/search_translation.rb', line 6 def self.search results = find_translation check_results(results) end |