-
Notifications
You must be signed in to change notification settings - Fork 9
Description
I'm trying to create a new Po object by adding entries from another Po object:
po1 = PoParser.parse_file('file.po')
po2 = PoParser::Po.new
po2 << po1.to_hWhere file.po looks like:
#
msgid ""
msgstr ""
"Project-Id-Version: VERSION\n"
"PO-Revision-Date: 2020-07-22 15:46+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE TEAM <EMAIL@ADDRESS>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. TRANSLATOR: This is used to categorise questions
msgctxt "Platform"
msgid "Assessment"
msgstr ""
#. TRANSLATOR: This is used to categorise questions
msgctxt "Platform"
msgid "Scores"
msgstr "Scores"But get the following error:
NoMethodError: undefined method `map' for #<String:0x000000010e5675c0>
Did you mean? tap
from /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/header.rb:97:in `convert_msgstr_to_hash'
NoMethodError:
undefined method `map' for #<String:0x0000000111652bf8>
Did you mean? tap
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/header.rb:97:in `convert_msgstr_to_hash'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/header.rb:14:in `initialize'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/po.rb:199:in `new'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/po.rb:199:in `add_header_entry'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/po.rb:190:in `add_entry'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/po.rb:177:in `import_hash'
# /Users/rodmurphy/.rbenv/versions/2.6.0/lib/ruby/gems/2.6.0/gems/PoParser-3.2.5/lib/poparser/po.rb:30:in `add'
The reason for this error is that the header object in po1 when PoParser::Po#to_h is called, is not getting exported in a manner that Po#add can understand. Note that I get the same error if I do po2 << po1.header.to_h
The trace is as follows:
Po#to_hruns,@header.to_his called- it in turn calls @entry.to_h
- this however, doesn't recognise the
msgstrof the header as anArraywhich you might expect for a multilinemsgstr(it's aPoParser::Messagewho'svalues are an Array) - thus it calls
to_son theMessageobject - this in turn concatenates each of the header entries into an un-delimited string.
It's this last resulting string that raises the error when attempting to create the header for the new Po object.
I'm not sure if this is the expected behaviour or whether my po file in incorrectly formatted?
What I'm really aiming to to here is to merge 2 po objects while keeping entries ordered alphabetically in the resulting po file, but the above is the simplest way to reproduce the bug.
I'm more than happy to create a PR assuming I've not missed something obvious.