Class: Babelyoda::Ibtool

Inherits:
Object
  • Object
show all
Defined in:
lib/babelyoda/ibtool.rb

Class Method Summary collapse

Class Method Details

.extract_strings(xib_filename, language) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/babelyoda/ibtool.rb', line 6

def self.extract_strings(xib_filename, language)
  Dir.mktmpdir do |dir|
    basename = File.basename(xib_filename, '.xib')
    strings_filename = File.join(dir, "#{basename}.strings")
    cmd = "ibtool --generate-strings-file '#{strings_filename}' '#{xib_filename}'"
    $logger.error "#{cmd}" unless Kernel.system(cmd)
    return Babelyoda::Strings.new(strings_filename, language).read!
  end
end

.import_strings(filename, strings_filename) ⇒ Object



42
43
44
45
46
# File 'lib/babelyoda/ibtool.rb', line 42

def self.import_strings(filename, strings_filename)
  ncmd = ['ibtool', '--import-strings-file', strings_filename, '--write', filename, filename]
  rc = Kernel.system(*ncmd)
  $logger.error "#{ncmd}" unless rc
end

.localize(source_xib_fn, target_xib_fn, strings_fn) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/babelyoda/ibtool.rb', line 16

def self.localize(source_xib_fn, target_xib_fn, strings_fn)
  # ibtool
  #   --strings-file path_to_strings/fr/MainWindow.strings                      # The latest localized strings for the French XIB
  #   --write path_to_project/fr.lproj/MainWindow.xib                           # The new French XIB that will be created
  #   path_to_project/English.lproj/MainWindow.new.xib                          # The new English XIB

  ncmd = ['ibtool', '--strings-file', strings_fn, '--write', target_xib_fn, source_xib_fn]
  rc = Kernel.system(*ncmd)
  $logger.error "#{ncmd}" unless rc
end

.localize_incrementally(source_xib_fn, target_xib_fn, strings_fn, old_source_xib_fn) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/babelyoda/ibtool.rb', line 27

def self.localize_incrementally(source_xib_fn, target_xib_fn, strings_fn, old_source_xib_fn)
  # ibtool
  #   --previous-file path_to_project/English.lproj/MainWindow.old.xib          # The old English XIB
  #   --incremental-file path_to_project/fr.lproj/MainWindow.old.xib            # The old French XIB
  #   --strings-file path_to_strings/fr/MainWindow.strings                      # The latest localized strings for the French XIB
  #   --localize-incremental
  #   --write path_to_project/fr.lproj/MainWindow.xib                           # The new French XIB that will be created
  #   path_to_project/English.lproj/MainWindow.new.xib                          # The new English XIB

  ncmd = ['ibtool', '--previous-file', old_source_xib_fn, '--incremental-file', target_xib_fn, 
    '--strings-file', strings_fn, '--localize-incremental', '--write', target_xib_fn, source_xib_fn]
  rc = Kernel.system(*ncmd)
  $logger.error "#{ncmd}" unless rc
end