Fix issue importing JSON strings containing line breaks.

Fixes #59
This commit is contained in:
Sebastian Celis 2014-06-10 10:22:30 -05:00
parent 0b52d8a346
commit f015bd2084
6 changed files with 32 additions and 0 deletions

View file

@ -35,6 +35,7 @@ module Twine
open(path) do |io|
json = JSON.load(io)
json.each do |key, value|
value.gsub!("\n","\\n")
set_translation_for_key(key, lang, value)
end
end

View file

@ -0,0 +1,5 @@
[[Line Break Strings]]
[line_breaking]
en = This\nstring\ncontains\nline\nbreaks
tags = tag1
fr = This\nstring\nalso\ncontains\nline\nbreaks

View file

@ -0,0 +1,3 @@
{
"line_breaking":"This\nstring\ncontains\nline\nbreaks"
}

View file

@ -0,0 +1,3 @@
{
"line_breaking":"This\nstring\nalso\ncontains\nline\nbreaks"
}

View file

@ -0,0 +1,4 @@
[[Line Break Strings]]
[line_breaking]
en = This\nstring\ncontains\nline\nbreaks
tags = tag1

View file

@ -111,4 +111,20 @@ class TwineTest < Test::Unit::TestCase
def test_generate_report_1
Twine::Runner.run(%w(generate-report test/fixtures/strings-1.txt))
end
def test_json_line_breaks_consume
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'strings.txt')
Twine::Runner.run(%W(consume-string-file test/fixtures/test-json-line-breaks/line-breaks.txt test/fixtures/test-json-line-breaks/line-breaks.json -l fr -o #{output_path}))
assert_equal(File.read('test/fixtures/test-json-line-breaks/consumed.txt'), File.read(output_path))
end
end
def test_json_line_breaks_generate
Dir.mktmpdir do |dir|
output_path = File.join(dir, 'en.json')
Twine::Runner.run(%W(generate-string-file test/fixtures/test-json-line-breaks/line-breaks.txt #{output_path}))
assert_equal(File.read('test/fixtures/test-json-line-breaks/generated.json'), File.read(output_path))
end
end
end