From c9f8f1c21af7ee41dbe2d2720bc4b3ff7caa9387 Mon Sep 17 00:00:00 2001 From: Sebastian Celis Date: Mon, 27 Feb 2012 16:00:05 -0600 Subject: [PATCH] Add the ability to write UTF-16 files. Issue #2 --- lib/twine/cli.rb | 3 +++ lib/twine/formatters/apple.rb | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/twine/cli.rb b/lib/twine/cli.rb index fa32da2..04fe1dc 100644 --- a/lib/twine/cli.rb +++ b/lib/twine/cli.rb @@ -56,6 +56,9 @@ module Twine opts.on('-a', '--all', 'Normally, when consuming a string file, Twine will ignore any string keys that do not exist in your master file. This flag will also cause any Android string files that are generated to include strings that have not yet been translated for the current language.') do |a| @options[:consume_generate_all] = true end + opts.on('-e', '--encoding ENCODING', 'Twine defaults to encoding all output files in UTF-8. This flag will tell Twine to use an alternate encoding for these files. For example, you could use this to write Apple .strings files in UTF-16. This flag currently only works with Apple .strings files and is currently only supported in Ruby 1.9.3 or greater.') do |e| + @options[:output_encoding] = e + end opts.on('-o', '--output-file OUTPUT_FILE', 'Write the new strings database to this file instead of replacing the original file. This flag is only useful when running the consume-string-file or consume-loc-drop commands.') do |o| @options[:output_path] = o end diff --git a/lib/twine/formatters/apple.rb b/lib/twine/formatters/apple.rb index 4570281..07c35e7 100644 --- a/lib/twine/formatters/apple.rb +++ b/lib/twine/formatters/apple.rb @@ -69,7 +69,8 @@ module Twine def write_file(path, lang) default_lang = @strings.language_codes[0] - File.open(path, 'w:UTF-8') do |f| + encoding = @options[:output_encoding] || 'UTF-8' + File.open(path, "w:#{encoding}") do |f| f.puts "/**\n * iOS Strings File\n * Generated by Twine\n * Language: #{lang}\n */" @strings.sections.each do |section| printed_section = false