Implemented #24 by adding option --only-untranslated to all formatters (that adopt the modular style).
This commit is contained in:
parent
87dfc80768
commit
d761eaa6c5
4 changed files with 25 additions and 1 deletions
|
@ -61,6 +61,9 @@ module Twine
|
|||
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
|
||||
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
|
||||
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
|
||||
|
|
|
@ -157,9 +157,13 @@ module Twine
|
|||
|
||||
def format_row(row, lang)
|
||||
value = row.translated_string_for_lang(lang)
|
||||
if value.nil? and not @options[:exclude_untranslated]
|
||||
|
||||
return if value && @options[:only_untranslated]
|
||||
|
||||
if value.nil? && (!@options[:exclude_untranslated] || @options[:only_untranslated])
|
||||
value = row.translated_string_for_lang(fallback_languages(lang))
|
||||
end
|
||||
|
||||
return nil unless value
|
||||
|
||||
result = ""
|
||||
|
|
9
test/fixtures/test-output-14.txt
vendored
Normal file
9
test/fixtures/test-output-14.txt
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Android Strings File -->
|
||||
<!-- Generated by Twine <%= Twine::VERSION %> -->
|
||||
<!-- Language: fr -->
|
||||
<resources>
|
||||
<!-- SECTION: My Strings -->
|
||||
<string name="key3">key3-english</string>
|
||||
<string name="key4">key4-english</string>
|
||||
</resources>
|
|
@ -139,4 +139,12 @@ class TwineTest < Test::Unit::TestCase
|
|||
assert_equal(File.read('test/fixtures/test-json-line-breaks/generated.json'), File.read(output_path))
|
||||
end
|
||||
end
|
||||
|
||||
def test_generate_string_file_14_only_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))
|
||||
assert_equal(ERB.new(File.read('test/fixtures/test-output-14.txt')).result, File.read(output_path))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue