diff --git a/lib/twine/cli.rb b/lib/twine/cli.rb index 42d985f..fa32da2 100644 --- a/lib/twine/cli.rb +++ b/lib/twine/cli.rb @@ -25,7 +25,7 @@ module Twine opts.separator '' opts.separator 'consume-string-file -- Slurps all of the strings from a translated strings file into the specified STRINGS_FILE. If you have some files returned to you by your translators you can use this command to incorporate all of their changes. This script will attempt to guess both the language and the format given the filename and extension. For example, "ja.strings" will assume that the file is a Japanese iOS strings file.' opts.separator '' - opts.separator 'generate-loc-drop -- Generates a zip archive of strings files in any format. The purpose of this command is to create a very simple archive that can be handed off to a translation team. The translation team can unzip the archive, translate all of the strings in the archived files, zip everything back up, and then hand that final archive back to be consumed by the consume-loc-drop command.' + opts.separator 'generate-loc-drop -- Generates a zip archive of strings files in any format. The purpose of this command is to create a very simple archive that can be handed off to a translation team. The translation team can unzip the archive, translate all of the strings in the archived files, zip everything back up, and then hand that final archive back to be consumed by the consume-loc-drop command. This command assumes that --all has been specified on the command line.' opts.separator '' opts.separator 'consume-loc-drop -- Consumes an archive of translated files. This archive should be in the same format as the one created by the generate-loc-drop command.' opts.separator '' @@ -53,8 +53,8 @@ module Twine end @options[:format] = lformat end - 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 force those missing strings to be added to your master file.') do |a| - @options[:consume_all] = true + 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('-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 @@ -128,6 +128,7 @@ module Twine raise Twine::Error.new 'Please only specify a single language for the consume-string-file command.' end when 'generate-loc-drop' + @options[:consume_generate_all] = true if @args.length == 3 @options[:output_path] = @args[2] elsif @args.length > 3 diff --git a/lib/twine/formatters/abstract.rb b/lib/twine/formatters/abstract.rb index 26a7ca0..ea0b637 100644 --- a/lib/twine/formatters/abstract.rb +++ b/lib/twine/formatters/abstract.rb @@ -16,7 +16,7 @@ module Twine def set_translation_for_key(key, lang, value) if @strings.strings_map.include?(key) @strings.strings_map[key].translations[lang] = value - elsif @options[:consume_all] + elsif @options[:consume_generate_all] STDERR.puts "Adding new string '#{key}' to strings data file." arr = @strings.sections.select { |s| s.name == 'Uncategorized' } current_section = arr ? arr[0] : nil diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb index 1e0b03c..fff1488 100644 --- a/lib/twine/formatters/android.rb +++ b/lib/twine/formatters/android.rb @@ -90,6 +90,10 @@ module Twine key = row.key value = row.translated_string_for_lang(lang, default_lang) + if !value && @options[:consume_generate_all] + value = row.translated_string_for_lang(@strings.language_codes[0]) + end + if value # if values is nil, there was no appropriate translation, so let Android handle the defaulting value = String.new(value) # use a copy to prevent modifying the original diff --git a/test/twine_test.rb b/test/twine_test.rb index 9839b06..fa54bc1 100644 --- a/test/twine_test.rb +++ b/test/twine_test.rb @@ -5,7 +5,7 @@ class TwineTest < Test::Unit::TestCase def test_generate_string_file_1 Dir.mktmpdir do |dir| output_path = File.join(dir, 'fr.xml') - Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path})) + Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --all)) assert_equal(File.read('test/fixtures/test-output-1.txt'), File.read(output_path)) end end