Class: Vocab::Extractor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vocab/extractor/base.rb

Direct Known Subclasses

Android, Rails

Class Method Summary collapse

Class Method Details

.current_pluralsObject



45
46
47
# File 'lib/vocab/extractor/base.rb', line 45

def current_plurals
  raise "current_plurals not implemented"
end

.current_stringsObject



41
42
43
# File 'lib/vocab/extractor/base.rb', line 41

def current_strings
  raise "current_strings not implemented"
end

.diff(previous, current) ⇒ Object

make a hash of all the translations that are new or changed in the current yml



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vocab/extractor/base.rb', line 19

def diff( previous, current )
  diff = {}
  current.each do |key, value|
    next if Vocab::Translator::Base.ignore_key?( key )

    previous_value = previous[ key ]
    if( previous_value.nil? || previous_value != value )
      diff[ key ] = value
    end
  end
  return diff
end

.extract(diff_path = nil, full_path = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/vocab/extractor/base.rb', line 5

def extract( diff_path = nil, full_path = nil )
  all_strings = current_strings
  all_plurals = current_plurals

  updated_strings = diff( previous_strings, all_strings )
  updated_plurals = diff( previous_plurals, all_plurals )
  write_diff( updated_strings, updated_plurals, diff_path )
  write_full( all_strings, all_plurals, full_path )
  update_settings
  mkdir_examples
  print_instructions
end

.git_path(path) ⇒ Object



70
71
72
# File 'lib/vocab/extractor/base.rb', line 70

def git_path( path )
  return File.expand_path( path ).gsub( "#{git_root}/", '' )
end

.git_rootObject



66
67
68
# File 'lib/vocab/extractor/base.rb', line 66

def git_root
  return `git rev-parse --show-toplevel`.strip
end

.mkdir_examplesObject



74
75
76
77
78
79
# File 'lib/vocab/extractor/base.rb', line 74

def mkdir_examples
  examples.each do |example|
    Vocab.ui.say( "Creating placeholder: #{example}" )
    FileUtils.mkdir_p( example )
  end
end

.previous_file(path, sha) ⇒ Object



61
62
63
64
# File 'lib/vocab/extractor/base.rb', line 61

def previous_file( path, sha )
  path = git_path( path )
  return `cd #{Vocab.root} && git show #{sha}:#{path}`
end

.previous_pluralsObject



49
50
51
# File 'lib/vocab/extractor/base.rb', line 49

def previous_plurals
  raise "previous_plurals not implemented"
end

.previous_stringsObject



37
38
39
# File 'lib/vocab/extractor/base.rb', line 37

def previous_strings
  raise "previous_strings not implemented"
end


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/vocab/extractor/base.rb', line 81

def print_instructions( values = {} )
instructions = <<-EOS

Extraction completed. To complete the translation:

1. Send the language files to the translators:

#{values[:diff]} for languages that are already in the app
#{values[:full]} for languages that need a complete translation

2. To integrate new translations:

Place completed translations under tmp/translations, for example:

#{values[:tree]}

3. Merge translations into the project with:

vocab merge rails

EOS
  Vocab.ui.say( instructions )
end

.update_settingsObject



32
33
34
35
# File 'lib/vocab/extractor/base.rb', line 32

def update_settings
  sha = Vocab.settings.update_translation
  Vocab.ui.say( "Updated current translation to #{sha}" )
end

.write_diff(diff, plurals, path) ⇒ Object



53
54
55
# File 'lib/vocab/extractor/base.rb', line 53

def write_diff( diff, plurals, path )
  raise "write_diff not implemented"
end

.write_full(diff, plurals, path) ⇒ Object



57
58
59
# File 'lib/vocab/extractor/base.rb', line 57

def write_full( diff, plurals, path )
  raise "write_full not implemented"
end