ruby-gettext / gettext

Gettext gem is a pure Ruby Localization(L10n) library and tool which is modeled after the GNU gettext package.
https://ruby-gettext.github.io/
68 stars 28 forks source link

MsgMerge no-wrap option with linebreaks #78

Closed gbp closed 4 years ago

gbp commented 4 years ago

I'm having issues with GetText::Tools::MsgMerge and the no-wrap option when working with content with linebreaks, for example this test fails:

    class TestNoWrapWithLineBrakes < self
      def po_content
        <<-'PO'
msgid "Line\nbreak"
msgstr "Line\nbreak"
        PO
      end

      def test_no_wrap
        @msgmerge.run("--update", "--no-wrap", @po_file_path, @po_file_path)
        assert_equal(<<-'PO', File.read(@po_file_path))
msgid "Line\nbreak"
msgstr "Line\nbreak"
        PO
      end
    end

Using GetText::Tools::MsgMerge returns:

msgid ""
"Line\n"
"brake"
msgstr ""
"Line\n"
"brake"

But from the command line:

$ msgmerge app.po app.po --update --no-wrap

We get... what we would expect:

msgid "Line\nbrake"
msgstr "Line\nbrake"
gbp commented 4 years ago

Also the same issue if the content uses \\n instead of \n

gbp commented 4 years ago

Maybe I'm wrong.

Looking more into this gem's source it seems there is a test ensuring new lines are retained and expanding my test PO file to:

msgid ""
msgstr ""
"Language: en\n"
"Content-Type: text/plain; charset=UTF-8"

msgid "Line\nbrake 1"
msgstr "Line\nbrake 1"

msgid ""
"Line\n"
"brake 2"
msgstr ""
"Line\n"
"brake 2"

Now when using the gettext command line tools (msgmerge/msgcat etc), with --no-wrap, results in:

msgid ""
msgstr ""
"Language: en\n"
"Content-Type: text/plain; charset=UTF-8\n"

msgid ""
"Line\n"
"brake 1"
msgstr ""
"Line\n"
"brake 1"

msgid ""
"Line\n"
"brake 2"
msgstr ""
"Line\n"
"brake 2"