-
Notifications
You must be signed in to change notification settings - Fork 9
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
Creating new Po from existing Po raises NoMethodError #27
Comments
It's nice to add the po1 = PoParser.parse_file('file_1.po')
po2 = PoParser.parse_file('file_2.po')
entries = po1.entries.to_h.merge(po2.to_h)
# Sort entries?
po3 = PoParser::Po.new(path: 'file_3.po')
po3.entries << entries
po3.save_file |
You probably don't want to do that and rather rely on the official gettext msgmerge utiliy for merging 2 po files. It does a lot more and is usually part of the process of a gettext based translation anyway. |
Thanks for the quick replies @arashm and @dfherr. Your suggestions will work, @arashm, however, this will not preserve the header. Similarly, I did have a solution where I determined the diffs from each of the hash representations of the files and either added or removed entries as necessary. As you allude to above, this results in a po file in which the entries are unsorted. I guess I could remove all non-header entries from I wasn't aware of |
I'm trying to create a new Po object by adding entries from another Po object:
Where file.po looks like:
But get the following error:
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 thatPo#add
can understand. Note that I get the same error if I dopo2 << po1.header.to_h
The trace is as follows:
Po#to_h
runs,@header.to_h
is calledmsgstr
of the header as anArray
which you might expect for a multilinemsgstr
(it's aPoParser::Message
who'svalue
s are an Array)to_s
on theMessage
objectIt'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.
The text was updated successfully, but these errors were encountered: