-
Notifications
You must be signed in to change notification settings - Fork 387
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
Multiple comments get ignored for same ID #845
Comments
@Bertg @tricoder42 I noticed this as well. However, if the different comments were to cause your translator to return separate translations for the same word given the comment (or context, as I'm thinking about it), how would we possibly encode it in the i.e Imagine the content for "long_value" is something like the English word "Lead" #: src/pages/Lingui.tsx:62
msgctxt "As in the element on the periodic table: Pb"
msgid "long_value"
msgstr "Lead"
#: src/pages/Lingui.tsx:69
#: src/pages/Lingui.tsx:74
msgctxt "The verb, meaning to control or guide"
msgid "long_value"
msgstr "Lead" And then the same translation key can be referenced contextually by some function or component like I think another part of the issue here would be conflating the idea of a comment with context. We use comments to provide our translators with context about the string and it's meaning, but gettext/po's more "programmatic" notion of context is slightly different, right? |
@Bertg Yeah, this will require a bit of refactoring in extraction script... @nakkamarra Unfortunately,
We should review Fluent before adding this feature to Lingui. I'm curious how they solve it. In the future I would like Lingui library to handle ICU Message Format as well as Fluent, so we need to find a common denominator for both. |
@nakkamarra I think context & comments should remain separate concepts. It can be that a comment is basically similar "CTA on a button", or "Button CTA". This does not warrant a separate translation or context. However, the comments may give a hint to a translator that something might be up in their specific language. Eg: "CTA to remove a user" and "CTA to delete item" on a string like this "Remove {item}". In English this is fine. However, in a language like french or other latin languages this might raise a concern as the value of {item} might change the translation entirely. In conclusion. I think we should have our cake and eat it too. We should have the multiple comments, and we should have msgctxt as well. |
I've been looking into this, and the initial capturing phase (capture comment per message) is a very easy change. diff --git a/packages/babel-plugin-extract-messages/src/index.ts b/packages/babel-plugin-extract-messages/src/index.ts
index 038ec9c1..a24d2614 100644
--- a/packages/babel-plugin-extract-messages/src/index.ts
+++ b/packages/babel-plugin-extract-messages/src/index.ts
@@ -56,7 +56,7 @@ export default function ({ types: t }) {
t.isIdentifier(node.object, { name: "i18n" }) &&
t.isIdentifier(node.property, { name: "_" })
- function collectMessage(path, file, props) {
+ function collectMessage(path, file, {comment, ...props}) {
const messages = file.get(MESSAGES)
const rootDir = file.get(CONFIG).rootDir
@@ -64,7 +64,7 @@ export default function ({ types: t }) {
.relative(rootDir, file.opts.filename)
.replace(/\\/g, "/")
const line = path.node.loc ? path.node.loc.start.line : null
- props.origin = [[filename, line]]
+ props.origin = [[filename, line, comment]]
addMessage(path, messages, props)
} This is a super simple change, but does change the entire internal representation quite a bit. Is it OK for you if I continue in this direction? |
It should be fine. Javascript doesn't have tuples, only arrays, so there's probably Feel free to go for it! 👍 You'll also need to change the |
@tricoder42 Yeah, after some brief reading and grepping, nothing immediately jumps out at me from there docs about how it is handled. I was under the impression that From the Maybe worth a separate issue for discussion of this? |
Yeah, definitely. Personally I don't see a reason why you'd need to separate msgid and msgctx, when you can use them both as an id. I guess it might be useful when you use natural language keys. |
@tricoder42 Well, I guess my issue with that is that it feels more like a hack than a solution, and it is unclear to me whether or not the context encoded in the IDs like that will be picked up a Translator / TMS the same way that a comment or a |
I have to follow @nakkamarra here. It is a hack. Say we follow the hack approach and write Writing If users consider If there is interest in this, I could have a look at bringing this into Lingui as well. |
FYI I @tricoder42 The comments fix is in. Had to do it differently still, but got it to work eventually ;) |
Yeah, that definitely highlights my concern with it, since that is my exact use-case. As for the support in Fluent, I'm beginning to think that it isn't supported, at least as per the use case I envision (the traditional gettext usage of So I envision it something like this, if in the future the library supports multiple message + file format combinations: Config defines PO as the file format: And as far as I know, the solution for I'm definitely interested in helping to solve this as well @Bertg @tricoder42, so please let me know if either of you would like to coordinate for getting a solution for context thought out and added to the library. |
@nakkamarra Well, first steps first would be to create a separate ticket for adding context support, instead of keeping the conversation here :)
This seems very reasonable as a suggestion. |
@nakkamarra I like your suggestion. I've just created #856 where I outlined what needs to be done. Feel free to ask me anything you might need if you want to work on this feature |
Describe the bug
A given translation ID may occur multiple times in the source code.
It is reasonable that some of these invocations have comments and other not, some comments may even be different.
Lingui only uses the comment of the first instance it find. If that instance does not have a comment, no comment is added to the PO file.
To Reproduce
Given the following file
when running
lingui extract
We get
Expected behavior
The PO file should contain all comments:
Additional context
The text was updated successfully, but these errors were encountered: