-
Notifications
You must be signed in to change notification settings - Fork 126
msgctxt extraction and compilation #34
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3beb400
added translate-context extraction capabilities (filters not parsed yet)
cristiano2lopes 28479f0
implemented msgctxt compilation
cristiano2lopes 4eb1ab3
always wrap the context bound translations in an array even if only one
cristiano2lopes cdae2c0
always wrapping context bound translations in an array and fixed
cristiano2lopes 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| <html> | ||
| <body> | ||
| <h1 translate translate-context="male">Hello!</h1> | ||
| <p translate translate-context="female">Hello!</p> | ||
| <h2 translate translate-context="male">Hello!</h2> | ||
| </body> | ||
| </html> |
This file contains hidden or 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,8 @@ | ||
| angular.module("myApp").controller("helloController", function (gettext) { | ||
| gettext(); // Should be ignored. | ||
| var myStringContext1 = gettextCatalog.getString("Hello!", null, "male"); | ||
| var myStringContext2 = gettextCatalog.getString("Hello!", null, "female"); | ||
| var myString2Context1 = gettextCatalog.getPlural(3, "Bird", "Birds", null, "cage"); | ||
| var myString2Context2 = gettextCatalog.getPlural(3, "Bird", "Birds", null, "free"); | ||
|
|
||
| }); |
This file contains hidden or 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,8 @@ | ||
| angular.module("myApp").controller("helloController", function (gettext) { | ||
| gettext(); // Should be ignored. | ||
| var myString = gettextCatalog.getString("Hello!"); | ||
| var myStringContext2 = gettextCatalog.getString("Hello!", null, "female"); | ||
| var myString2Context1 = gettextCatalog.getPlural(3, "Bird", "Birds", null, "cage"); | ||
| var myString2Context2 = gettextCatalog.getPlural(3, "Bird", "Birds", null, "free"); | ||
|
|
||
| }); |
This file contains hidden or 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,6 @@ | ||
| <html> | ||
| <body> | ||
| <h1 translate translate-context="male">Hello!</h1> | ||
| <p translate>Hello!</p> | ||
| </body> | ||
| </html> |
This file contains hidden or 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,6 @@ | ||
| <html> | ||
| <body> | ||
| <h1 translate>Hello!</h1> | ||
| <p translate translate-context="female">Hello!</p> | ||
| </body> | ||
| </html> |
This file contains hidden or 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 hidden or 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,37 @@ | ||
| msgid "" | ||
| msgstr "" | ||
| "Language: pt-BR\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: 8bit\n" | ||
| "Plural-Forms: nplurals=2; plural=n>1;\n" | ||
| "Project-Id-Version: \n" | ||
| "POT-Creation-Date: \n" | ||
| "PO-Revision-Date: \n" | ||
| "Last-Translator: \n" | ||
| "Language-Team: \n" | ||
| "X-Generator: Poedit 1.5.7\n" | ||
|
|
||
| #: test/fixtures/homonyms.js | ||
| msgctxt "cage" | ||
| msgid "Bird" | ||
| msgid_plural "Birds" | ||
| msgstr[0] "Pássaro Oprimido" | ||
| msgstr[1] "Pássaros Oprimidos" | ||
|
|
||
| #: test/fixtures/homonyms.js | ||
| msgctxt "free" | ||
| msgid "Bird" | ||
| msgid_plural "Birds" | ||
| msgstr[0] "Pássaro Livre" | ||
| msgstr[1] "Pássaros Livres" | ||
|
|
||
| #: test/fixtures/homonyms.js | ||
| msgctxt "male" | ||
| msgid "Hello!" | ||
| msgstr "Olá!" | ||
|
|
||
| #: test/fixtures/homonyms.js | ||
| msgctxt "female" | ||
| msgid "Hello!" | ||
| msgstr "Olá Olá!" |
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.
This is really hard to read. What exactly is happening here?
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.
@rubenv It's not great I agree.
The complexity introduced arises from the need to abort the extraction if the user doesn't indicate a context for a msgid that has (or will) provide a context for the same msgid.
If in some place a msgctx is indicated for a msgid then all the msgid appearences must be accompanied by a msgctx.
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.
@cristiano2lopes Is that a feature of the gettext API? It seems very limiting to be forced to annotate every instance of a msgid with a context just because you want one instance contextualized. Is there something I'm missing that makes this necessary?
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.
I cannot back my decision based on the get text API (I haven't read it). The reference i read was:
"The context serves to disambiguate messages with the same untranslated-string. It is possible to have several entries with the same untranslated-string in a PO file, provided that they each have a different context. Note that an empty context string and an absent msgctxt line do not mean the same thing." from here.
You can't have duplicate msgid without a msgctx so you assume some default context (empty?) for the ones that don't provide a context or prevent it from happening. Also how to decide which translation to retrieve if one does not have a context?
I can be wrong (and this complicates the implementation) so maybe we should change it.