Merge pull request #268 from scelis/fix/escape-gettext-quotes

Escape quotes in the gettext formatter
This commit is contained in:
Sebastian Celis 2019-02-24 11:10:06 -06:00 committed by GitHub
commit 28825fcf78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -76,15 +76,15 @@ module Twine
end
def format_key(key)
"msgctxt \"#{key}\"\n"
"msgctxt \"#{escape_quotes(key)}\"\n"
end
def format_base_translation(definition)
"msgid \"#{definition.translations[@default_lang]}\"\n"
"msgid \"#{escape_quotes(definition.translations[@default_lang])}\"\n"
end
def format_value(value)
"msgstr \"#{value}\"\n"
"msgstr \"#{escape_quotes(value)}\"\n"
end
end
end

View file

@ -0,0 +1,10 @@
msgid ""
msgstr ""
"Language: en"
"X-Generator: Twine <%= Twine::VERSION %>"
# SECTION: Section
msgctxt "key"
msgid "foo \"bar\" baz"
msgstr "foo \"bar\" baz"

View file

@ -413,6 +413,16 @@ class TestGettextFormatter < FormatterTest
language = %w(en-GB de fr).sample
assert_equal language, @formatter.determine_language_given_path("/output/#{language}/#{@formatter.default_file_name}")
end
def test_quoted_strings
formatter = Twine::Formatters::Gettext.new
formatter.twine_file = build_twine_file "not-a-lang-code" do
add_section "Section" do
add_definition key: "foo \"bar\" baz"
end
end
assert_equal content('formatter_gettext_quotes.po'), formatter.format_file('en')
end
end
class TestTizenFormatter < FormatterTest