Skip to content

Commit

Permalink
fix: output multiple origins on separate lines (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
tricoder42 authored Aug 26, 2018
1 parent c254d91 commit c587586
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
16 changes: 14 additions & 2 deletions packages/cli/src/api/formats/__snapshots__/po.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Object {
origin: undefined,
translation: Message with description,
},
withOrigin: Object {
withMultipleOrigins: Object {
description: undefined,
obsolete: false,
origin: Array [
Expand All @@ -39,6 +39,17 @@ Object {
2,
],
],
translation: Message with multiple origin,
},
withOrigin: Object {
description: undefined,
obsolete: false,
origin: Array [
Array [
src/App.js,
4,
],
],
translation: Message with origin,
},
}
Expand All @@ -61,7 +72,8 @@ msgstr ""
msgid "static"
msgstr "Static message"
#: src/App.js:4, src/Component.js:2
#: src/App.js:4
#: src/Component.js:2
msgid "withOrigin"
msgstr "Message with origin"
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/src/api/formats/fixtures/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ msgstr ""
msgid "static"
msgstr "Static message"

#: src/App.js:4, src/Component.js:2
#: src/App.js:4
msgid "withOrigin"
msgstr "Message with origin"

#: src/App.js:4
#: src/Component.js:2
msgid "withMultipleOrigins"
msgstr "Message with multiple origin"

#. Description is comment from developers to translators
msgid "withDescription"
msgstr "Message with description"
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/api/formats/po.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ const serialize = R.compose(
return [
"",
message.description && `#. ${message.description}`,
message.origin && `#: ${prettyOrigin(message.origin)}`,
...(message.origin
? // print one origin per line (don't join multiple origins with comma)
message.origin.map(origin => `#: ${prettyOrigin([origin])}`)
: []),
message.obsolete && `#, obsolete`,
`msgid "${escape(key)}"`,
`msgstr "${escape(translation)}"`
Expand All @@ -61,7 +64,8 @@ const serialize = R.compose(
function parseOrigin(origins) {
if (!origins) return

return origins.split(", ").map(origin => origin.split(":"))
// split by comma or newlines, but don't remember matched delimiter
return origins.split(/(?:, |\n)/).map(origin => origin.split(":"))
}

const deserialize = R.map(message => ({
Expand Down

0 comments on commit c587586

Please sign in to comment.