leonelquinteros / gotext

Go (Golang) GNU gettext utilities package
Other
432 stars 58 forks source link

Format quotation marks and newlines for PO export #61

Closed felixvd closed 2 years ago

felixvd commented 2 years ago

Fixes https://github.com/leonelquinteros/gotext/issues/60.

As described in the issue, this:

    po := gotext.NewPo()
    strings := map[string]string{"myid": "test string\nwith \"newline\""}
    for k, v := range strings {
        po.Set(k, v)
    }
    po_bytes, _ := po.MarshalText()
    fmt.Println(string(po_bytes))

currently outputs this:

msgid ""
msgstr ""

msgid "myid"
msgstr "test string
with "newline""

This breaks format and causes xgettext to throw errors if the file is used. After this PR, the output is:

[...]
msgid "myid"
msgstr "test string"
"with \"newline\""

My apologies for not adding tests. Please feel free to edit/push to this branch.

leonelquinteros commented 2 years ago

Hi @felixvd , thanks for your contribution!

It looks like this PR is breaking the build process (didn't reached the tests). Could you review that to ensure at least old tests are passing?

Also, adding tests for this use cases would be welcome, otherwise we'll wait until there are tests in place to cover for them before merging the PR.

felixvd commented 2 years ago

My bad, I edited quickly in the Github web interface.

Fixed and added a test.

leonelquinteros commented 2 years ago

@felixvd Please check the test error now.

leonelquinteros commented 2 years ago

Thanks for your contribution @felixvd !!