babelyoda 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/bin/babelyoda CHANGED
@@ -2,18 +2,19 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'fileutils'
5
- require 'plist'
6
5
  require 'term/ansicolor'
7
6
  require 'tmpdir'
8
7
  require 'yaml'
9
8
 
10
9
  include Term::ANSIColor
11
10
 
11
+ require 'babelyoda/options'
12
+ require 'babelyoda/strings'
13
+
12
14
  # Main block
13
15
 
14
16
  def main
15
- banner
16
- check_args
17
+ $config = BabelYoda::Options.parse
17
18
  setup
18
19
  print_config
19
20
  prepare_folders
@@ -32,34 +33,13 @@ end
32
33
 
33
34
  # Aux methods
34
35
 
35
- def banner
36
- puts "Babel Yoda v1.2.0"
37
- puts "© 2010 Andrey Subbotin <andrey@subbotin.me>"
38
- end
39
-
40
- def usage
41
- puts ""
42
- puts "Usage: babelyoda [<rules.babelyoda>]"
43
- puts ""
44
- puts "<rules.babelyoda> = babel yoda config file, default is rules.babelyoda"
45
- end
46
-
47
- def check_args
48
- if ARGV.length > 1
49
- usage
50
- exit 1
51
- end
52
- end
53
-
54
36
  def setup
55
- $config = Hash.new
56
37
  global_config_filename = File.expand_path('~/.babelyoda')
57
38
  $config.merge!(YAML.load_file(global_config_filename)) if File.exist?(global_config_filename)
58
- config = YAML.load_file(ARGV[0].nil? ? 'rules.babelyoda' : ARGV[0])
39
+ config = YAML.load_file($config['rules'])
59
40
  config['tmp_dir'] = File.join Dir.tmpdir, "epl.babelyoda.#{$$}"
60
41
  config['src_dir'] = File.join config['tmp_dir'], 'src'
61
42
  config['startwd'] = Dir.getwd
62
- config['src_lang'] = Plist::parse_xml(config['plist'])['CFBundleDevelopmentRegion']
63
43
  config['src_lang_lproj'] = config['src_lang'] + '.lproj'
64
44
  config['src_lang_lproj_dir'] = File.join(config['strings_folder'], config['src_lang_lproj'])
65
45
  config['src_lang_code_strings_file'] = File.join(config['src_lang_lproj_dir'], 'Localizable.strings')
@@ -237,6 +217,8 @@ def genstrings(files, output_path)
237
217
  files_safe = escape_cmd_args(files)
238
218
  rc = exe "genstrings -o '#{output_path}' #{files_safe}"
239
219
  error "Failed to generate strings" unless rc
220
+ strings_file = File.join(output_path, 'Localizable.strings')
221
+ BabelYoda::StringsHelper.safe_init_strings_file strings_file
240
222
  end
241
223
 
242
224
  def gen_src_xib_strings
@@ -257,6 +239,7 @@ def gen_xib_strings(xib)
257
239
  strings = tmp_filename_for_xib_strings(xib)
258
240
  rc = exe "ibtool --generate-strings-file '#{strings}' '#{xib}'"
259
241
  error "Failed to generate strings for file '#{xib}'" unless rc
242
+ BabelYoda::StringsHelper.safe_init_strings_file strings
260
243
  strings
261
244
  end
262
245
 
@@ -265,9 +248,13 @@ def merge_strings(src_strings, dst_strings)
265
248
  puts "DST_STRINGS: #{dst_strings}"
266
249
  targets.each do |target|
267
250
  status "MERGING STRINGS AT '#{src_strings}' INTO '#{target}'"
268
- FileUtils.touch target
269
- rc = exe "wincent-strings-util --base '#{src_strings}' --merge '#{target}' --output '#{target}'"
270
- error "Failed to merge '#{src_strings}' into '#{target}'" unless rc
251
+ FileUtils.mkdir_p File.split(target)[0], :verbose => true
252
+ if File.exists? target
253
+ rc = exe "wincent-strings-util --base '#{src_strings}' --merge '#{target}' --output '#{target}'"
254
+ error "Failed to merge '#{src_strings}' into '#{target}'" unless rc
255
+ else
256
+ FileUtils.cp src_strings, target, :verbose => true
257
+ end
271
258
  end
272
259
  end
273
260
 
@@ -363,6 +350,8 @@ def localize_xibs_incrementally
363
350
  FileUtils.cp src_xib, dst_xib, :preserve => true, :verbose => true
364
351
  old_dst_xib = old_xib_for_xib_lang(dst_xib, lang)
365
352
  FileUtils.cp dst_xib, old_dst_xib, :preserve => true, :verbose => true
353
+
354
+ BabelYoda::StringsHelper.safe_init_strings_file dst_strings
366
355
 
367
356
  ncmd = ['ibtool', '--previous-file', "'#{old_dst_xib}'",
368
357
  '--incremental-file', "'#{old_src_xib}'",
@@ -370,7 +359,6 @@ def localize_xibs_incrementally
370
359
  '--localize-incremental',
371
360
  '--write', "#{dst_xib}",
372
361
  "#{src_xib}"].join(' ')
373
- puts "XIB-CMD: #{ncmd}"
374
362
  rc = exe ncmd
375
363
  error "Failed to localize a XIB incrementally" unless rc
376
364
  end
@@ -0,0 +1 @@
1
+ ��
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'ostruct'
5
+
6
+ module BabelYoda
7
+ class Options
8
+
9
+ #
10
+ # Return a structure describing the options.
11
+ #
12
+ def self.parse
13
+ # The options specified on the command line will be collected in *options*.
14
+ # We set default values here.
15
+ options = { 'rules' => 'rules.babelyoda' }
16
+
17
+ optparser = OptionParser.new do |opts|
18
+ opts.banner = "Usage: babelyoda [options]"
19
+
20
+ opts.separator ""
21
+ opts.separator "Common options:"
22
+
23
+ # Optional argument; multi-line description.
24
+ opts.on("-r", "--rules <RULES-FILE>",
25
+ "Use the specified rules file.",
26
+ "Default is 'babelyoda.rules'.") do |rules|
27
+ options['rules'] = rules
28
+ end
29
+
30
+ # No argument, shows at tail. This will print an options summary.
31
+ opts.on_tail("-h", "--help", "Show this message") do
32
+ puts opts
33
+ exit
34
+ end
35
+ end
36
+
37
+ optparser.parse!
38
+ options
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ module BabelYoda
2
+ class StringsHelper
3
+ def self.safe_init_strings_file(path)
4
+ unless File.exists? path
5
+ empty_strings_file = File.join File.dirname(__FILE__), '..', '..', 'data', 'empty.strings'
6
+ FileUtils.mkdir_p File.split(path)[0], :verbose => true
7
+ FileUtils.cp empty_strings_file, path, :verbose => true
8
+ end
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 1.2.0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrey Subbotin
@@ -56,8 +56,9 @@ files:
56
56
  - LICENSE
57
57
  - README.rdoc
58
58
  - VERSION
59
- - bin/babelyoda
60
- - lib/babelyoda.rb
59
+ - data/empty.strings
60
+ - lib/babelyoda/options.rb
61
+ - lib/babelyoda/strings.rb
61
62
  has_rdoc: true
62
63
  homepage: http://github.com/eploko/babelyoda
63
64
  licenses: []
data/lib/babelyoda.rb DELETED
File without changes