Module: I18nChecker::Locale::Methods

Included in:
I18nChecker::Locale
Defined in:
lib/i18n_checker/locale.rb

Instance Method Summary collapse

Instance Method Details

#load_of(locale_files) ⇒ I18nChecker::Locale::Files

Read specified translation file



12
13
14
15
16
# File 'lib/i18n_checker/locale.rb', line 12

def load_of(locale_files)
  files = locale_files.delete_if { |resource| ::File.directory?(resource) }.to_a
  loaded_locale_files = files.map { |locale_file| I18nChecker::Locale::File.load_yaml_file(locale_file) }
  Files.new(loaded_locale_files)
end

#text_collector_of(file_extname, caches:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/i18n_checker/locale.rb', line 33

def text_collector_of(file_extname, caches:)
  case file_extname
  when '.haml'
    I18nChecker::Locale::Collector::Haml.new(caches)
  when '.rb'
    I18nChecker::Locale::Collector::Ruby.new(caches)
  else
    raise StandardError, "not support #{extname} file" # FIXME: throw custom error!!
  end
end

#texts_of(resources) ⇒ I18nChecker::Locale::Texts

Collect translation text from specified file list



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/i18n_checker/locale.rb', line 21

def texts_of(resources)
  caches = I18nChecker::Cache::Files.new

  files = resources.delete_if { |resource| ::File.directory?(resource) }.to_a
  grouped_files = files.group_by { |file| ::File.extname(file) }
  grouped_locale_texts = grouped_files.map do |k, v|
    text_collector_of(k, caches: caches).collect_all(v)
  end
  result = I18nChecker::Locale::Texts.new
  grouped_locale_texts.reduce(result) { |locale_texts, n| locale_texts.concat(n) }.uniq!
end