Ignore commented out lines in Django .PO files (fixes #286)
This commit is contained in:
parent
8566a0b70e
commit
42895063e1
3 changed files with 20 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
|||
module Twine
|
||||
module Formatters
|
||||
# For a description of the .po file format, see https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html
|
||||
class Django < Abstract
|
||||
def format_name
|
||||
'django'
|
||||
|
@ -14,9 +15,9 @@ module Twine
|
|||
end
|
||||
|
||||
def read(io, lang)
|
||||
comment_regex = /#\. *"?(.*)"?$/
|
||||
key_regex = /msgid *"(.*)"$/
|
||||
value_regex = /msgstr *"(.*)"$/m
|
||||
comment_regex = /^\s*#\. *"?(.*)"?$/
|
||||
key_regex = /^msgid *"(.*)"$/
|
||||
value_regex = /^msgstr *"(.*)"$/m
|
||||
|
||||
while line = io.gets
|
||||
comment_match = comment_regex.match(line)
|
||||
|
@ -58,7 +59,7 @@ module Twine
|
|||
end
|
||||
|
||||
def format_section_header(section)
|
||||
"#--------- #{section.name} ---------#\n"
|
||||
"# --------- #{section.name} --------- #\n"
|
||||
end
|
||||
|
||||
def format_definition(definition, lang)
|
||||
|
|
4
test/fixtures/formatter_django.po
vendored
4
test/fixtures/formatter_django.po
vendored
|
@ -5,7 +5,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
||||
#--------- Section 1 ---------#
|
||||
# --------- Section 1 --------- #
|
||||
|
||||
#. comment key1
|
||||
# base translation: "value1-english"
|
||||
|
@ -17,7 +17,7 @@ msgid "key2"
|
|||
msgstr "value2-english"
|
||||
|
||||
|
||||
#--------- Section 2 ---------#
|
||||
# --------- Section 2 --------- #
|
||||
|
||||
# base translation: "value3-english"
|
||||
msgid "key3"
|
||||
|
|
|
@ -554,6 +554,19 @@ class TestDjangoFormatter < 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_ignores_commented_out_strings
|
||||
content = <<-EOCONTENT
|
||||
#~ msgid "foo"
|
||||
#~ msgstr "This should be ignored"
|
||||
EOCONTENT
|
||||
|
||||
io = StringIO.new(content)
|
||||
|
||||
@formatter.read io, 'en'
|
||||
|
||||
assert_nil @empty_twine_file.definitions_by_key["foo"]
|
||||
end
|
||||
end
|
||||
|
||||
class TestFlashFormatter < FormatterTest
|
||||
|
|
Reference in a new issue