github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/bin/show-missing-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  @exit_code = 0
     8  
     9  def install_gi18n
    10    output = `go get -u github.com/maximilien/i18n4go/gi18n`
    11    unless $?.exitstatus == 0
    12      puts "Cannot install latest gi18n tool to verify strings:\n#{output}"
    13      exit 1
    14    end
    15  end
    16  
    17  def show_missing_strings(english_reference_file, directory_to_verify)
    18    puts "\nVerifying: \n\t #{english_reference_file} \n\t #{directory_to_verify}\n\n"
    19  
    20    result = system("gi18n -c show-missing-strings -d #{directory_to_verify} --i18n-strings-filename #{english_reference_file}")
    21    unless result
    22      puts "===> Failed Verification!"
    23      unless File.exist?(english_reference_file)
    24        puts "#{english_reference_file} does not exist."
    25        exit 1
    26      end
    27      @exit_code = 1
    28    end
    29  end
    30  
    31  def get_matching_directory(path_to_i18n)
    32    i18n_resources_dir = File.join("cf", "i18n", "resources", "en")
    33    File.expand_path(File.dirname(path_to_i18n.gsub(i18n_resources_dir, '')))
    34  end
    35  
    36  def run
    37    path = File.join(CLI_ROOT, *%w[cf i18n resources en *])
    38    english_json_files = `find #{path} -type f`.split
    39  
    40    english_json_files.each do |english_reference_file|
    41      show_missing_strings(english_reference_file, get_matching_directory(english_reference_file))
    42    end
    43  end
    44  
    45  install_gi18n
    46  run
    47  exit(@exit_code)