-
Notifications
You must be signed in to change notification settings - Fork 394
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
feat: Implement gettext plurals for PO files #677
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f3c002b
Manual rebase of po-gettext onto main branch
iStefo 866f220
Merge branch 'main' of github.com:lingui/js-lingui into main
iStefo 095d9f6
po-gettext: Improve code and tests
iStefo 42a8a98
po-gettext: Add docs
iStefo 066ed79
Merge branch 'main' of github.com:lingui/js-lingui into main
iStefo 58cb1c1
po-gettext: Fix TS errors in test
iStefo 9d1e8ed
po-gettext: Fix issue with msgid generation (and incorrect docs)
iStefo 22adc5d
Merge branch 'main' of github.com:lingui/js-lingui into main
iStefo 8deba5d
po-gettext: fix compiler erros
iStefo d4d24da
po-gettext: Store context information in extracted comments section
iStefo 4c15013
Merge branch 'main' of github.com:lingui/js-lingui into main
iStefo ea2b8c6
po-gettext: Align API with regular po module
iStefo ec91a88
po-gettext: Ignore CLDR plural cases that are not supported by gettext
iStefo a8842a6
po-gettext: Update docs to reflect gettext's limitation regarding fra…
iStefo 4833f7c
po-gettext: Fix incompatibility issue with node 10
iStefo d775589
po-gettext: Attempt fix text on windows
iStefo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
251 changes: 251 additions & 0 deletions
251
packages/cli/src/api/formats/__snapshots__/po-gettext.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`po-gettext format should convert ICU plural messages to gettext plurals 1`] = ` | ||
msgid "" | ||
msgstr "" | ||
"POT-Creation-Date: 2018-08-27 10:00+0000\\n" | ||
"Mime-Version: 1.0\\n" | ||
"Content-Type: text/plain; charset=utf-8\\n" | ||
"Content-Transfer-Encoding: 8bit\\n" | ||
"X-Generator: @lingui/cli\\n" | ||
"Language: en\\n" | ||
|
||
msgctxt "pluralize_on=count" | ||
msgid "message_with_id_and_octothorpe" | ||
msgid_plural "message_with_id_and_octothorpe_plural" | ||
msgstr[0] "Singular" | ||
msgstr[1] "Number is #" | ||
|
||
msgctxt "pluralize_on=someCount" | ||
msgid "message_with_id" | ||
msgid_plural "message_with_id_plural" | ||
msgstr[0] "Singular case with id" | ||
msgstr[1] "Case number {someCount} with id" | ||
|
||
msgctxt "icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount" | ||
msgid "Singular case" | ||
msgid_plural "Case number {anotherCount}" | ||
msgstr[0] "Singular case" | ||
msgstr[1] "Case number {anotherCount}" | ||
|
||
msgctxt "pluralize_on=count" | ||
msgid "message_with_id_but_without_translation" | ||
msgid_plural "message_with_id_but_without_translation_plural" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgctxt "icu=%7Bcount%2C+plural%2C+one+%7BSingular+automatic+id+no+translation%7D+other+%7BPlural+%7Bcount%7D+automatic+id+no+translation%7D%7D&pluralize_on=count" | ||
msgid "Singular automatic id no translation" | ||
msgid_plural "Plural {count} automatic id no translation" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
`; | ||
|
||
exports[`po-gettext format should convert gettext plurals to ICU plural messages 1`] = ` | ||
Object { | ||
message_with_id: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: {someCount, plural, one {Singular case} other {Case number {someCount}}}, | ||
}, | ||
message_with_id_but_without_translation: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: , | ||
}, | ||
{anotherCount, plural, one {Singular case} other {Case number {anotherCount}}}: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: {anotherCount, plural, one {Singular case} other {Case number {anotherCount}}}, | ||
}, | ||
{count, plural, one {Singular} other {Plural}}: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: , | ||
}, | ||
} | ||
`; | ||
|
||
exports[`po-gettext format should correct badly used comments 1`] = ` | ||
Object { | ||
withDescriptionAndComments: Object { | ||
comment: Single description only, | ||
comments: Array [ | ||
Translator comment, | ||
Second description?, | ||
], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Second description joins translator comments, | ||
}, | ||
withMultipleDescriptions: Object { | ||
comment: First description, | ||
comments: Array [ | ||
Second comment, | ||
Third comment, | ||
], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Extra comments are separated from the first description line, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`po-gettext format should read catalog in pofile format 1`] = ` | ||
Object { | ||
obsolete: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: true, | ||
origin: Array [], | ||
translation: Is marked as obsolete, | ||
}, | ||
static: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Static message, | ||
}, | ||
veryLongString: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me?" he thought. It wasn't a dream. His room, a proper human, | ||
}, | ||
withComments: Object { | ||
comment: undefined, | ||
comments: Array [ | ||
Translator comment, | ||
This one might come from developer, | ||
], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Support translator comments separately, | ||
}, | ||
withDescription: Object { | ||
comment: Description is comment from developers to translators, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Message with description, | ||
}, | ||
withFlags: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [ | ||
fuzzy, | ||
otherFlag, | ||
], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: Keeps any flags that are defined, | ||
}, | ||
withMultipleOrigins: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [ | ||
Array [ | ||
src/App.js, | ||
4, | ||
], | ||
Array [ | ||
src/Component.js, | ||
2, | ||
], | ||
], | ||
translation: Message with multiple origin, | ||
}, | ||
withOrigin: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [ | ||
Array [ | ||
src/App.js, | ||
4, | ||
], | ||
], | ||
translation: Message with origin, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`po-gettext format should throw away additional msgstr if present 1`] = ` | ||
Object { | ||
withMultipleTranslation: Object { | ||
comment: undefined, | ||
comments: Array [], | ||
flags: Array [], | ||
obsolete: false, | ||
origin: Array [], | ||
translation: This is just fine, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`po-gettext format should write catalog in pofile format 1`] = ` | ||
msgid "" | ||
msgstr "" | ||
"POT-Creation-Date: 2018-08-27 10:00+0000\\n" | ||
"Mime-Version: 1.0\\n" | ||
"Content-Type: text/plain; charset=utf-8\\n" | ||
"Content-Transfer-Encoding: 8bit\\n" | ||
"X-Generator: @lingui/cli\\n" | ||
"Language: en\\n" | ||
|
||
msgid "static" | ||
msgstr "Static message" | ||
|
||
#: 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" | ||
|
||
msgid "withDescription" | ||
msgstr "Message with description" | ||
|
||
# Translator comment | ||
# This one might come from developer | ||
msgid "withComments" | ||
msgstr "Support translator comments separately" | ||
|
||
#~ msgid "obsolete" | ||
#~ msgstr "Obsolete message" | ||
|
||
#, fuzzy,otherFlag | ||
msgid "withFlags" | ||
msgstr "Keeps any flags that are defined" | ||
|
||
msgid "veryLongString" | ||
msgstr "One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. \\"What's happened to me?\\" he thought. It wasn't a dream. His room, a proper human" | ||
|
||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
msgid "" | ||
msgstr "" | ||
"POT-Creation-Date: 2018-08-27 10:00+0000\n" | ||
"Mime-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=utf-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"X-Generator: @lingui/cli\n" | ||
"Language: en\n" | ||
|
||
msgctxt "pluralize_on=someCount" | ||
msgid "message_with_id" | ||
msgid_plural "message_with_id_plural" | ||
msgstr[0] "Singular case" | ||
msgstr[1] "Case number {someCount}" | ||
|
||
msgctxt "icu=%7BanotherCount%2C+plural%2C+one+%7BSingular+case%7D+other+%7BCase+number+%7BanotherCount%7D%7D%7D&pluralize_on=anotherCount" | ||
msgid "Singular case" | ||
msgid_plural "Case number {anotherCount}" | ||
msgstr[0] "Singular case" | ||
msgstr[1] "Case number {anotherCount}" | ||
|
||
msgctxt "pluralize_on=count" | ||
msgid "message_with_id_but_without_translation" | ||
msgid_plural "message_with_id_but_without_translation_plural" | ||
msgstr[0] "" | ||
msgstr[1] "" | ||
|
||
msgctxt "icu=%7Bcount%2C+plural%2C+one+%7BSingular%7D+other+%7BPlural%7D%7D&pluralize_on=count" | ||
msgid "Singular" | ||
msgid_plural "Plural" | ||
msgstr[0] "" | ||
msgstr[1] "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary for this feature to use
msgctx
? There's actually another PR #856 implementing the originalmsgctx
behavior from Gettext.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the original ICU message in
msgctx
is clearly a workaround and not using the field as intended. In earlier versions, only thepluralize_on
value was stored there, which I need to reconstruct the original ICU message.The full ICU message is stored s.t.
msgid
can be restored for messages where the developer does not use custom IDs, as the ICU cases in development language are used formsgid
andmsgid_plural
, so items look like this:I could also store the querystring encoded data in a new type of comment, say ' #?foo=bar' and, when converting from po to ICU, iterate comments until I find one that matches the format. What do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we need to use comments to store any required metadata. You could even have one comment per line:
but whatever works for you the best 👍
There're several types of comments available in gettext:
Not sure which are supported by the PO library we use, but I guess this would be a good fit for
extracted-comments
.I'm open to any suggestions :)