Class: Vocab::Extractor::Android

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

Constant Summary collapse

DIFF =
'strings.diff.xml'
FULL =
'strings.full.xml'
STRINGS_XML =
'res/values/strings.xml'

Class Method Summary collapse

Methods inherited from Base

diff, extract, git_path, git_root, mkdir_examples, previous_file, update_settings

Class Method Details

.current_plurals(path = nil) ⇒ Object



22
23
24
25
# File 'lib/vocab/extractor/android.rb', line 22

def current_plurals( path = nil )
  path ||= "#{Vocab.root}/#{STRINGS_XML}"
  return Vocab::Translator::Android.plurals_from_xml( path )
end

.current_strings(path = nil) ⇒ Object



11
12
13
14
# File 'lib/vocab/extractor/android.rb', line 11

def current_strings( path = nil )
  path ||= "#{Vocab.root}/#{STRINGS_XML}"
  return Vocab::Translator::Android.hash_from_xml( path )
end

.examples(locales_dir = nil) ⇒ Object



43
44
45
46
47
48
# File 'lib/vocab/extractor/android.rb', line 43

def examples( locales_dir = nil )
  locales_dir ||= "#{Vocab.root}/res/values"
  return Vocab::Translator::Android.locales( locales_dir ).collect do |locale|
    "tmp/translations/values-#{locale}"
  end
end

.previous_plurals(path = nil) ⇒ Object



27
28
29
30
31
# File 'lib/vocab/extractor/android.rb', line 27

def previous_plurals( path = nil )
  path ||= STRINGS_XML
  tmpfile = tmp_file( path )
  return Vocab::Translator::Android.plurals_from_xml( tmpfile )
end

.previous_strings(path = nil) ⇒ Object



16
17
18
19
20
# File 'lib/vocab/extractor/android.rb', line 16

def previous_strings( path = nil )
  path ||= STRINGS_XML
  tmpfile = tmp_file( path )
  return Vocab::Translator::Android.hash_from_xml( tmpfile )
end


50
51
52
53
54
55
56
57
58
59
# File 'lib/vocab/extractor/android.rb', line 50

def print_instructions( values = {} )
  values[ :diff ] = DIFF
  values[ :full ] = FULL
  values[ :tree ] = <<-EOS
tmp/translations/values-es/strings.xml
tmp/translations/values-zh-rCN/strings.xml
  EOS

  super( values )
end

.tmp_file(path) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/vocab/extractor/android.rb', line 61

def tmp_file( path )
  sha = Vocab.settings.last_translation
  xml = previous_file( path, sha )
  tmpfile = "#{Vocab.root}/tmp/last_translation/#{File.basename(path)}"
  FileUtils.mkdir_p( File.dirname( tmpfile ) )
  File.open( tmpfile, 'w' ) { |f| f.write( xml ) }
  return tmpfile
end

.write_diff(strings, plurals, path = nil) ⇒ Object



33
34
35
36
# File 'lib/vocab/extractor/android.rb', line 33

def write_diff( strings, plurals, path = nil )
  path ||= "#{Vocab.root}/#{DIFF}"
  Vocab::Translator::Android.write( strings, plurals, path )
end

.write_full(strings, plurals, path = nil) ⇒ Object



38
39
40
41
# File 'lib/vocab/extractor/android.rb', line 38

def write_full( strings, plurals, path = nil )
  path ||= "#{Vocab.root}/#{FULL}"
  Vocab::Translator::Android.write( strings, plurals, path )
end