Module: I18n::Processes::Command::Commands::Preprocessing
- Includes:
- I18n::Processes::Command::Collection, Path
- Included in:
- Missing, I18n::Processes::Commands
- Defined in:
- lib/i18n/processes/command/commands/preprocessing.rb
Instance Method Summary collapse
- #keys_source(dic, path, locale) ⇒ Object
- #origin_file_read(file) ⇒ Object
- #preprocessing(opt = {}) ⇒ Object
Methods included from I18n::Processes::Command::Collection
Instance Method Details
#keys_source(dic, path, locale) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/i18n/processes/command/commands/preprocessing.rb', line 48 def keys_source(dic, path, locale) filename = path + locale File.delete(filename) if File.exist?(filename) local_file = File.new(filename, 'w') dic.map do |key, value| value.include?("\n") ? local_file.write("#{key}=#{value}") : local_file.write("#{key}=#{value}\n") end local_file.close end |
#origin_file_read(file) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/i18n/processes/command/commands/preprocessing.rb', line 31 def origin_file_read(file) {}.tap do |a| File.open(file).read.each_line do |line| next if line =~ /^#/ || line == "\n" || !line.include?('.') if line.include?('\':') line.gsub!(/'|,/, '') key = line.split(': ').first.delete(' ') value = line.split(': ').last else key = line.split('=').first.delete(' ') value = line.split('=').last end a[key] = value end end end |
#preprocessing(opt = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i18n/processes/command/commands/preprocessing.rb', line 19 def preprocessing(opt = {}) locale = opt[:locales].include?(base_locale) ? 'zh-CN' : opt[:locales].first dic = {} origin_files(locale).flatten.each do |file| # dic.merge!(origin_file_read(file)) { |key, v1, v2| fail "conflict: #{key}: #{v1}, #{v2} in #{file}" unless v1 == v2 } dic.merge!(origin_file_read(file)) end path = compare_path.first keys_source(dic, path, locale) $stderr.puts Rainbow('fetch all keys and values from origin files').green if locale == base_locale end |