Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple_po_parser throws an error on multiline strings which do not start with an empty string #3

Closed
mgruner opened this issue Mar 18, 2022 · 3 comments

Comments

@mgruner
Copy link
Contributor

mgruner commented Mar 18, 2022

We have a valid po file generated from Weblate:

❯ msgfmt -c i18n/zammad.zh-cn.po
❯ echo $?
0

It contains such multiline strings, which are obviously valid:

msgid ""
"By default, the follow-up check is done via the subject of an email. This "
"setting lets you add more fields for which the follow-up check will be "
"executed."
msgstr "默认情况下,通过电子邮件的主题进行跟进检查。这个设置允许你增加更多的字段执行"
"跟进检查。"

But they cause the following error:

SimplePoParser::ParserError: SimplePoParser::ParserErrorSyntax error in lines
Syntax error in msgctxt
Syntax error in msgid
Syntax error in msgstr
Unexpected content after expected message end "\"跟进检"
Parseing result before error: '{:reference=>"db/seeds/settings.rb", :msgid=>["", "By default, the follow-up check is done via the subject of an email. This ", "setting lets you add more fields for which the follow-up check will be ", "executed."], :msgstr=>"默认情况下,通过电子邮件的主题进行跟进检查。这个设置允许你增加更多的字段执行"}'
SimplePoParser filtered backtrace: SimplePoParser::ParserError
/usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:179:in msgstr'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:134:inmsgid'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:114:in msgctxt'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:51:inlines'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:75:in comment'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:49:inlines'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser/parser.rb:25:in parse'
    from /usr/local/rvm/gems/ruby-2.7.4/gems/simple_po_parser-1.1.5/lib/simple_po_parser.rb:19:inparse_message'
    

It seems that such lines are (incorrectly?) expected to be having final white space. Similar multiline strings which contain trailing spaces are processed correctly.

Any help would be appreciated.

zammad-sync pushed a commit to zammad/zammad that referenced this issue Mar 18, 2022
@dfherr
Copy link
Collaborator

dfherr commented Mar 18, 2022

The problem is it expects multiline messages to start with an empty line like seen in the specification examples https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html

This came up earlier in the more high-level parser that uses this one as its core arashm/PoParser#24

I would accept a PR that fixes this and doesn't assume multilines start with an empty string, as it's strictly not part of the specification. However, from my experience running msgfmt always creates that syntax with a leading empty string.

@dfherr dfherr changed the title simple_po_parser throws an error on multiline strings which have no space at the end simple_po_parser throws an error on multiline strings which do not start with an empty string Mar 18, 2022
@mgruner
Copy link
Contributor Author

mgruner commented Mar 18, 2022

I can confirm this. In our other instances where it does work, multiline strings start with "".

@mgruner
Copy link
Contributor Author

mgruner commented Mar 18, 2022

@dfherr sent a PR as #4. Would this be acceptable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants