-
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
Fix how Entry#to_h represents Po entries with multiple lines #28
base: master
Are you sure you want to change the base?
Conversation
Sorry for late response, I was traveling. I'll have a look this afternoon. |
@arashm it's still WIP - the specs are passing but when I try it in my project, it's not working as expected. Multiline comments are being output incorrectly by Trying to get my head around it, but I think fundamentally the way I'm hoping to go back to it tomorrow or early next week, I'll try to reproduce that scenario in a spec. |
0a90086
to
a7cd96f
Compare
a7cd96f
to
cecd72c
Compare
@arashm this should we resolved now. Let me know if you spot any issues |
@arashm sorry to bug you again. Did you get a chance to look at this. I'd love to just bump the version I have rather than point our app at my fork. |
@rod-murphy could you elaborate why this is necessary? That looks like an unnecessary hack to me. |
To add to my previous question. Using this test file:
Parsing it and using |
Thanks for the reply @dfherr.
As I said above, it's to address the issue where the array produced by In my mind, if I can export an Po object as and array of hashes and must import entries by passing a hash (or array of hashes), then this should be reversible? You can see this when you run
The resulting hashes are not correctly added to a Po object when |
@rod-murphy that doesn't really clear up why I agree that it makes sense that these are reversible, but why adding another syntax to accessing plural msgstr? |
I was checking your original issue #27, and as I remember the issue was not being able to parse the header, because the def convert_msgstr_to_hash(msgstr)
value = msgstr.value.is_a?(String) ? msgstr.value.split("\\n") : msgstr.value
options_array = value.map do |options|
... Wouldn't this be sufficient for your case? |
7621538
to
02994f2
Compare
02994f2
to
9aa72ad
Compare
The reason this is necessary is because of how writer methods are defined. i.e. it's not possible to have a method named To better cover all case and make is a little clearer, I've updated the Entry spec to make things a bit clearer with the following test: it 'should show a hash representation of a complex entry' do
# Ensure the to_h method is reversible
# From SimplePoParser::Parser - https://github.com/experteer/simple_po_parser/blob/v1.1.5/spec/simple_po_parser/parser_spec.rb#L31
entry_hash = {
:translator_comment => ["translator-comment", ""],
:extracted_comment => "extract",
:reference => ["reference1", "reference2"],
:flag => "flag",
:previous_msgctxt => "previous context",
:previous_msgid => ["", "multiline\\n", "previous messageid"],
:previous_msgid_plural => "previous msgid_plural",
:msgctxt => "Context",
:msgid => "msgid",
:msgid_plural => ["", "multiline msgid_plural\\n", ""],
"msgstr[0]" => "msgstr 0",
"msgstr[1]" => ["", "msgstr 1 multiline 1\\n", "msgstr 1 line 2\\n"],
"msgstr[2]" => "msgstr 2"
}
entry = PoParser::Entry.new(entry_hash)
expect(entry.to_h).to eq(entry_hash)
end Essentially, for @arashm your solution doesn't go far enough. If you run the above spec, you can see that in addition to header entries, strings and multiline forms of |
Sorry again for the delay, I will hopefully look into it today after work. |
Your suggestion seems to change the behavior of |
Thanks @arashm and again sorry for the delay coming back to you. Generally your fix will work for the most part (I've added a few comments to your commit), however, when run against's the test hash from Can you help me understand where I'm changing the behaviour of |
It's kinda weird that every message in this topic start with an excuse for the delay on responses, but anyway, I'm sorry 😅 I (again) totally forgot about this for a while.
The behaviour change is exactly about your comment here. The current version of [1] pry(main)> load 'lib/poparser.rb'
=> true
[2] pry(main)> po = PoParser.parse_file('test/complex_entry.po')
=> <PoParser::Po, Translated: 1(100.0%) Untranslated: 0(0.0%) Fuzzy: 0(0.0%)>
[3] pry(main)> po.to_h
=> [{:translator_comment=>"translator-comment\n",
:extracted_comment=>"extract",
:reference=>"reference1\nreference2",
:flag=>"flag",
:previous_msgctxt=>"previous context",
:previous_msgid=>"multiline\\nprevious messageid",
:previous_msgid_plural=>"previous msgid_plural",
:msgctxt=>"Context",
:msgid=>"msgid",
:msgid_plural=>"multiline msgid_plural\\n",
"msgstr[0]"=>"msgstr 0",
"msgstr[1]"=>"msgstr 1 multiline 1\\nmsgstr 1 line 2\\n",
"msgstr[2]"=>"msgstr 2"}] You can see |
As described in #27 multi-line po entries did not export in such a was as they could be successfully reimported when
Entry#to_h
was called on each Entry object.The same thing was happening to multi-line comment entries.
I've changed
Entry
so that it accepts plural form msgstr entries asmsgstr_n
instance variable and writer methods, but exports these (viato_h
) using originalmsgstr[n]
notations.Fixes #27