#92 merged --only-untranslated and --exclude-untranslated options into --include option.

This commit is contained in:
Sebastian Ludwig 2015-09-25 09:54:07 +02:00
parent d761eaa6c5
commit e7703507cb
3 changed files with 18 additions and 11 deletions

View file

@ -58,11 +58,18 @@ module Twine
opts.on('-a', '--consume-all', 'Normally, when consuming a string file, Twine will ignore any string keys that do not exist in your master file.') do |a|
@options[:consume_all] = true
end
opts.on('-x', '--exclude-untranslated', 'This flag will cause any string files that are generated to not include strings that have not yet been translated for the current language.') do |s|
@options[:exclude_untranslated] = true
opts.on('-i', '--include SET', "This flag will determine which strings are included when generating strings files. It's possible values:",
" all: All strings both translated and untranslated for the specified language are included. This is the default value.",
" translated: Only translated strings are included.",
" untranslated: Only untranslated strings are included.") do |set|
set = set.downcase
unless ['all', 'translated', 'untranslated'].include?(set)
STDERR.puts "Invalid set: #{set}"
end
@options[:include] = set
end
opts.on('-u', '--only-untranslated', 'This flag will cause any generated files to include only the strings that have not been translated.') do |c|
@options[:only_untranslated] = true
unless @options[:include]
@options[:include] = 'all'
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

View file

@ -158,9 +158,9 @@ module Twine
def format_row(row, lang)
value = row.translated_string_for_lang(lang)
return if value && @options[:only_untranslated]
return if value && @options[:include] == 'untranslated'
if value.nil? && (!@options[:exclude_untranslated] || @options[:only_untranslated])
if value.nil? && @options[:include] != 'translated'
value = row.translated_string_for_lang(fallback_languages(lang))
end

View file

@ -68,10 +68,10 @@ class TwineTest < Test::Unit::TestCase
end
end
def test_exclude_untranslated
def test_include_translated
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} --exclude-untranslated))
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --include translated))
assert_equal(ERB.new(File.read('test/fixtures/test-output-13.txt')).result, File.read(output_path))
end
end
@ -140,10 +140,10 @@ class TwineTest < Test::Unit::TestCase
end
end
def test_generate_string_file_14_only_untranslated
def test_generate_string_file_14_include_untranslated
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'only_untranslated.xml')
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --only-untranslated -l fr))
output_path = File.join(dir, 'include_untranslated.xml')
Twine::Runner.run(%W(generate-string-file test/fixtures/strings-1.txt #{output_path} --include untranslated -l fr))
assert_equal(ERB.new(File.read('test/fixtures/test-output-14.txt')).result, File.read(output_path))
end
end