diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb index 2531ce0..92cbcaa 100644 --- a/lib/twine/formatters/android.rb +++ b/lib/twine/formatters/android.rb @@ -71,6 +71,7 @@ module Twine value.gsub!('\\\'', '\'') value.gsub!('\\"', '"') value = iosify_substitutions(value) + value.gsub!(/(\\u0020)*|(\\u0020)*\z/) { |spaces| ' ' * (spaces.length / 6) } else value = "" end @@ -129,6 +130,8 @@ module Twine value = CGI.escapeHTML(value) # 3) fix substitutions (e.g. %s/%@) value = androidify_substitutions(value) + # 4) replace beginning and end spaces with \0020. Otherwise Android strips them. + value.gsub!(/\A *| *\z/) { |spaces| '\u0020' * spaces.length } comment = row.comment if comment diff --git a/test/fixtures/en-3.xml b/test/fixtures/en-3.xml new file mode 100644 index 0000000..4e77462 --- /dev/null +++ b/test/fixtures/en-3.xml @@ -0,0 +1,8 @@ + + + + + + + \u0020string with spaces\u0020\u0020 + diff --git a/test/fixtures/test-output-10.txt b/test/fixtures/test-output-10.txt new file mode 100644 index 0000000..d08351c --- /dev/null +++ b/test/fixtures/test-output-10.txt @@ -0,0 +1,9 @@ + + + + + + + + string with space\u0020 + diff --git a/test/fixtures/test-output-11.txt b/test/fixtures/test-output-11.txt new file mode 100644 index 0000000..d1ec0a6 --- /dev/null +++ b/test/fixtures/test-output-11.txt @@ -0,0 +1,9 @@ +[[Uncategorized]] + [string_with_spaces] + en = ` string with spaces ` + +[[My Strings]] + [key with space ] + en = `string with space ` + tags = tag1 + comment = String ends with space diff --git a/test/twine_test.rb b/test/twine_test.rb index 8f61e51..38ef26e 100644 --- a/test/twine_test.rb +++ b/test/twine_test.rb @@ -52,6 +52,14 @@ class TwineTest < Test::Unit::TestCase end end + def test_generate_string_file_7 + Dir.mktmpdir do |dir| + output_path = File.join(dir, 'en.xml') + Twine::Runner.run(%W(generate-string-file test/fixtures/strings-2.txt #{output_path} -t tag1)) + assert_equal(ERB.new(File.read('test/fixtures/test-output-10.txt')).result, File.read(output_path)) + end + end + def test_consume_string_file_1 Dir.mktmpdir do |dir| output_path = File.join(dir, 'strings.txt') @@ -92,6 +100,14 @@ class TwineTest < Test::Unit::TestCase end end + def test_consume_string_file_6 + Dir.mktmpdir do |dir| + output_path = File.join(dir, 'strings.txt') + Twine::Runner.run(%W(consume-string-file test/fixtures/strings-2.txt test/fixtures/en-3.xml -o #{output_path} -l en -a)) + assert_equal(File.read('test/fixtures/test-output-11.txt'), File.read(output_path)) + end + end + def test_generate_report_1 Twine::Runner.run(%w(generate-report test/fixtures/strings-1.txt)) end