parent
0b52d8a346
commit
f015bd2084
6 changed files with 32 additions and 0 deletions
|
@ -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
|
||||
|
|
5
test/fixtures/test-json-line-breaks/consumed.txt
vendored
Normal file
5
test/fixtures/test-json-line-breaks/consumed.txt
vendored
Normal 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
|
3
test/fixtures/test-json-line-breaks/generated.json
vendored
Normal file
3
test/fixtures/test-json-line-breaks/generated.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"line_breaking":"This\nstring\ncontains\nline\nbreaks"
|
||||
}
|
3
test/fixtures/test-json-line-breaks/line-breaks.json
vendored
Normal file
3
test/fixtures/test-json-line-breaks/line-breaks.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"line_breaking":"This\nstring\nalso\ncontains\nline\nbreaks"
|
||||
}
|
4
test/fixtures/test-json-line-breaks/line-breaks.txt
vendored
Normal file
4
test/fixtures/test-json-line-breaks/line-breaks.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
[[Line Break Strings]]
|
||||
[line_breaking]
|
||||
en = This\nstring\ncontains\nline\nbreaks
|
||||
tags = tag1
|
|
@ -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
|
||||
|
|
Reference in a new issue