Class: I18n::Translate::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/translator.rb

Instance Method Summary collapse

Constructor Details

#initialize(lang, opts = {}) ⇒ Translator

Returns a new instance of Translator.



9
10
11
# File 'lib/i18n/translator.rb', line 9

def initialize(lang, opts={})
  @translate = I18n::Translate::Translate.new(lang, opts)
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/i18n/translator.rb', line 13

def run
  stat = @translate.stat
  @translate.merge.select{|x| x["flag"] != "ok"}.each_with_index do |entry, i|
    next_entry = false
    while not next_entry
      puts ""
      puts ""
      puts "[#{@translate.default_file} + #{@translate.lang_file}]"
      puts "(#{i+1}/#{stat[:fuzzy]}) #{entry["key"]} (#{entry["flag"]})"
      puts "comment: #{entry["comment"]}" unless entry["comment"].empty?
      puts "old default: #{entry["old_default"]}" unless entry["old_default"].empty?
      puts "old translation: #{entry["old_translation"]}" unless entry["old_translation"].empty?
      puts "default: #{entry["default"]}"
      puts "translation: #{entry["translation"]}"
      puts ""
      puts "Actions:"
      puts "n (next) t (translate) f (change flag) c (comment) s (save) q (save & quit) x(exit no saving)"
      action = STDIN.readline.strip
      puts ""
      case action
      when 'n'
        next_entry = true
      when 't'
        puts "Enter translation:"
        entry["translation"] = STDIN.readline.strip
        entry["flag"] = "ok" unless entry["translation"].empty?
        @translate.assign( [entry] )
        puts "Flag sets to #{entry["flag"]}"
      when 'f'
        puts "Change flag to:"
        puts "o (ok), i (incomplete), c (changed), u (untranslated)"
        f = STDIN.readline.strip
        I18n::Translate::FLAGS.each do |fname|
          if fname[0,1] == f
            entry["flag"] = fname
            break
          end
        end
        @translate.assign( [entry] )
        puts "Flag sets to #{entry["flag"]}"
      when 'c'
        puts "Enter comment:"
        entry["comment"] = STDIN.readline.strip
        @translate.assign( [entry] )
        puts "Comment has changed."
      when 's'
        @translate.export!
        puts "Translation saved"
      when 'q'
        @translate.export!
        puts "Translation saved"
        exit
      when 'x'
        exit
      end # case
    end # while
  end # each_with_index

  @translate.export!
  @translate.reload!
end