github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/bin/verify-strings (about) 1 #!/usr/bin/env ruby 2 3 ENV['GOPATH']="#{ENV['HOME']}/go" 4 ENV['PATH']="#{ENV['PATH']}:#{ENV['GOPATH']}/bin" 5 CLI_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..")) 6 7 @verbose = false 8 9 def split_locale(locale) 10 return locale.split('_') 11 end 12 13 def install_gi18n 14 output = `go get -u github.com/maximilien/i18n4go/gi18n` 15 unless $?.exitstatus == 0 16 puts "Cannot install latest gi18n tool to verify strings:\n#{output}" 17 exit 1 18 end 19 end 20 21 def verify_strings(english_reference_file, locale_to_verify) 22 language_to_verify, _ = split_locale(locale_to_verify) 23 en_path = "/en/".gsub("/", File::SEPARATOR) 24 lang_path = "/#{language_to_verify}/".gsub("/", File::SEPARATOR) 25 file_to_verify = english_reference_file.gsub("en_US", locale_to_verify).gsub(en_path, lang_path) 26 27 if @verbose 28 puts "Verifying: \n\t #{english_reference_file} \n\t #{file_to_verify}" 29 end 30 31 result = system("gi18n -c verify-strings -source-language en_US -f #{english_reference_file} -languages #{locale_to_verify} -language-files #{file_to_verify}") 32 unless result 33 puts "failed verification:" 34 unless File.exist?(file_to_verify) 35 puts "#{file_to_verify} does not exist." 36 exit 1 37 end 38 39 `find #{file_to_verify}.* -type f`.split.each do |output_info| 40 puts output_info 41 puts File.read(output_info) 42 end 43 exit 1 44 end 45 end 46 47 def run 48 path = "#{CLI_ROOT}/cf/i18n/resources/en/*".gsub("/", File::SEPARATOR) 49 english_json_files = `find #{path} -type f`.split 50 supported_locales = Dir.glob("#{CLI_ROOT}/cf/i18n/resources/**/*.all.json".gsub("/", File::SEPARATOR)).map do |filepath| 51 filepath.split(File::SEPARATOR).last.gsub(".all.json", "") 52 end.uniq 53 54 english_json_files.each do |english_reference_file| 55 supported_locales.each do |locale| 56 verify_strings(english_reference_file, locale) 57 end 58 end 59 end 60 61 @verbose = ARGV.include?("-v") 62 install_gi18n 63 run