Class: I18n::Processes::Reports::Spreadsheet

Inherits:
Base
  • Object
show all
Includes:
Path
Defined in:
lib/i18n/processes/reports/spreadsheet.rb

Constant Summary

Constants included from Logging

Logging::MUTEX, Logging::PROGRAM_NAME

Instance Attribute Summary

Attributes inherited from Base

#task

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Logging

log_error, log_stderr, log_verbose, log_warn, program_name, warn_deprecated

Constructor Details

This class inherits a constructor from I18n::Processes::Reports::Base

Instance Method Details

#find_missing(locale = nil) ⇒ Object



38
39
40
41
42
43
# File 'lib/i18n/processes/reports/spreadsheet.rb', line 38

def find_missing(locale = nil)
  path = './tmp/'
  comp_dic = get_dic(path + locale)
  base_dic = get_dic(path + base_locale)
  base_dic.select { |k,v| (base_dic.keys - comp_dic.keys).include?(k)}
end

#missing_report(locale) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/i18n/processes/reports/spreadsheet.rb', line 11

def missing_report(locale)
  path = 'tmp/missing_keys/'
  FileUtils::mkdir_p path  unless Dir.exist?path
  file = "#{path}missing_keys_#{locale}"
  report = File.new(file, 'w')
  report.write("# 说明:以#开头的行,表示key对应的中文翻译\n# 下一行'='左边为key,'='右边需要填上对应的#{locale}翻译: \n")
  report.write("\n\n# =======================  missing keys list =============================\n\n")
  find_missing(locale).map do |k,v|
    report.write("# #{v}")
    report.write("#{k}=\n\n")
  end
  report.close
  $stderr.puts Rainbow("missing report saved to #{file}\n").red.bright
end

#translated_files(locale) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/i18n/processes/reports/spreadsheet.rb', line 26

def translated_files(locale)
  path = translated_path.first unless translated_path == []
  dic = get_dic("./tmp/#{locale}")
  FileUtils.rm_f Dir.glob("./#{path}**/**") unless Dir["./#{path}**/**"].size.zero?
  origin_files = origin_files(base_locale).flatten
  # $stderr.puts Rainbow origin_files
  origin_files.each do |origin_file|
    translated_file(origin_file,"#{path}#{locale}/",  dic)
  end
  $stderr.puts Rainbow("translated files saved to #{path}\n").green
end