Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix issue importing JSON strings containing line breaks.

Fixes #59
  • Loading branch information...
commit f015bd20843d21a2f34913269d43ce52e99e91dc 1 parent 0b52d8a
@scelis scelis authored
View
1  lib/twine/formatters/jquery.rb
@@ -35,6 +35,7 @@ def read_file(path, lang)
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
5 test/fixtures/test-json-line-breaks/consumed.txt
@@ -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
3  test/fixtures/test-json-line-breaks/generated.json
@@ -0,0 +1,3 @@
+{
+"line_breaking":"This\nstring\ncontains\nline\nbreaks"
+}
View
3  test/fixtures/test-json-line-breaks/line-breaks.json
@@ -0,0 +1,3 @@
+{
+"line_breaking":"This\nstring\nalso\ncontains\nline\nbreaks"
+}
View
4 test/fixtures/test-json-line-breaks/line-breaks.txt
@@ -0,0 +1,4 @@
+[[Line Break Strings]]
+ [line_breaking]
+ en = This\nstring\ncontains\nline\nbreaks
+ tags = tag1
View
16 test/twine_test.rb
@@ -111,4 +111,20 @@ def test_consume_string_file_6
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
Please sign in to comment.
Something went wrong with that request. Please try again.