bin/babelyoda in babelyoda-1.2.0 vs bin/babelyoda in babelyoda-1.3.0

- old
+ new

@@ -1,21 +1,22 @@ #!/usr/bin/env ruby require 'rubygems' require 'fileutils' -require 'plist' require 'term/ansicolor' require 'tmpdir' require 'yaml' include Term::ANSIColor +require 'babelyoda/options' +require 'babelyoda/strings' + # Main block def main - banner - check_args + $config = BabelYoda::Options.parse setup print_config prepare_folders init_lproj_dirs apply_incremental_translations @@ -30,38 +31,17 @@ success "All done!" end # Aux methods -def banner - puts "Babel Yoda v1.2.0" - puts "© 2010 Andrey Subbotin <andrey@subbotin.me>" -end - -def usage - puts "" - puts "Usage: babelyoda [<rules.babelyoda>]" - puts "" - puts "<rules.babelyoda> = babel yoda config file, default is rules.babelyoda" -end - -def check_args - if ARGV.length > 1 - usage - exit 1 - end -end - def setup - $config = Hash.new global_config_filename = File.expand_path('~/.babelyoda') $config.merge!(YAML.load_file(global_config_filename)) if File.exist?(global_config_filename) - config = YAML.load_file(ARGV[0].nil? ? 'rules.babelyoda' : ARGV[0]) + config = YAML.load_file($config['rules']) config['tmp_dir'] = File.join Dir.tmpdir, "epl.babelyoda.#{$$}" config['src_dir'] = File.join config['tmp_dir'], 'src' config['startwd'] = Dir.getwd - config['src_lang'] = Plist::parse_xml(config['plist'])['CFBundleDevelopmentRegion'] config['src_lang_lproj'] = config['src_lang'] + '.lproj' config['src_lang_lproj_dir'] = File.join(config['strings_folder'], config['src_lang_lproj']) config['src_lang_code_strings_file'] = File.join(config['src_lang_lproj_dir'], 'Localizable.strings') config['initial_strings_file'] = File.join(config['strings_folder'], 'Localizable.strings') $config.merge!(config) @@ -235,10 +215,12 @@ def genstrings(files, output_path) files_safe = escape_cmd_args(files) rc = exe "genstrings -o '#{output_path}' #{files_safe}" error "Failed to generate strings" unless rc + strings_file = File.join(output_path, 'Localizable.strings') + BabelYoda::StringsHelper.safe_init_strings_file strings_file end def gen_src_xib_strings status "GENERATING STRINGS FILES FOR THE SOURCE LANGUAGE XIBS" src_xib_files.each do |xib| @@ -255,21 +237,26 @@ def gen_xib_strings(xib) strings = tmp_filename_for_xib_strings(xib) rc = exe "ibtool --generate-strings-file '#{strings}' '#{xib}'" error "Failed to generate strings for file '#{xib}'" unless rc + BabelYoda::StringsHelper.safe_init_strings_file strings strings end def merge_strings(src_strings, dst_strings) targets = dst_strings.is_a?(String) ? [dst_strings] : dst_strings puts "DST_STRINGS: #{dst_strings}" targets.each do |target| status "MERGING STRINGS AT '#{src_strings}' INTO '#{target}'" - FileUtils.touch target - rc = exe "wincent-strings-util --base '#{src_strings}' --merge '#{target}' --output '#{target}'" - error "Failed to merge '#{src_strings}' into '#{target}'" unless rc + FileUtils.mkdir_p File.split(target)[0], :verbose => true + if File.exists? target + rc = exe "wincent-strings-util --base '#{src_strings}' --merge '#{target}' --output '#{target}'" + error "Failed to merge '#{src_strings}' into '#{target}'" unless rc + else + FileUtils.cp src_strings, target, :verbose => true + end end end def extract_untranslated_src_code_strings tmp_strings_file = File.join($config['tmp_dir'], 'Localizable.strings') @@ -361,17 +348,18 @@ old_src_xib = old_xib_for_xib_lang(src_xib, $config['src_lang']) FileUtils.cp src_xib, old_src_xib, :preserve => true, :verbose => true FileUtils.cp src_xib, dst_xib, :preserve => true, :verbose => true old_dst_xib = old_xib_for_xib_lang(dst_xib, lang) FileUtils.cp dst_xib, old_dst_xib, :preserve => true, :verbose => true + + BabelYoda::StringsHelper.safe_init_strings_file dst_strings ncmd = ['ibtool', '--previous-file', "'#{old_dst_xib}'", '--incremental-file', "'#{old_src_xib}'", '--strings-file', "'#{dst_strings}'", '--localize-incremental', '--write', "#{dst_xib}", "#{src_xib}"].join(' ') - puts "XIB-CMD: #{ncmd}" rc = exe ncmd error "Failed to localize a XIB incrementally" unless rc end end end