-
Notifications
You must be signed in to change notification settings - Fork 122
Add an option to include original line numbers within extracted message information #71
Comments
Yeah this is totally possible to add. What do you want to consider as the start of the message being defined? I'm thinking it should be the nested object in I think it makes sense to only save this information to the JSON files when an option is enabled on the Babel plugin. |
I agree. Considering the nested object in |
@antoinepm I have something working. Let me know your thoughts on whether you want all of this data and if you think it should be structured differently. Here's an example from running it on this file: [
{
"id": "app.title",
"defaultMessage": "React Intl Translations Example",
"file": "src/client/components/app.js",
"start": {
"line": 23,
"column": 20
},
"end": {
"line": 26,
"column": 22
}
},
{
"id": "app.locales_menu_heading",
"defaultMessage": "Locales:",
"file": "src/client/components/app.js",
"start": {
"line": 32,
"column": 20
},
"end": {
"line": 35,
"column": 22
}
}
] The name of the option is: |
This option will provide metadata in the Message Description for the file and location in the file where the message was defined. When enabled and running it on [this file][1] you'll get this result: ```json [ { "id": "app.title", "defaultMessage": "React Intl Translations Example", "file": "src/client/components/app.js", "start": { "line": 23, "column": 20 }, "end": { "line": 26, "column": 22 } }, { "id": "app.locales_menu_heading", "defaultMessage": "Locales:", "file": "src/client/components/app.js", "start": { "line": 32, "column": 20 }, "end": { "line": 35, "column": 22 } } ] ``` Fixes #71 [1]: https://github.com/yahoo/react-intl/blob/25f3f64d86ac86281157117b5bdb9fa30d1d615f/examples/translations/src/client/components/app.js
The data presented above looks great to me. Although I would use only some parts for my own purposes, I think that all of it should be included, as it is more self-explanatory than my initial suggestion. I like the extractSourceLocation parameter name, too. |
Cool! I'll get this out soon… but maybe after the long weekend here in the US. |
This option will provide metadata in the Message Description for the file and location in the file where the message was defined. When enabled and running it on [this file][1] you'll get this result: ```json [ { "id": "app.title", "defaultMessage": "React Intl Translations Example", "file": "src/client/components/app.js", "start": { "line": 23, "column": 20 }, "end": { "line": 26, "column": 22 } }, { "id": "app.locales_menu_heading", "defaultMessage": "Locales:", "file": "src/client/components/app.js", "start": { "line": 32, "column": 20 }, "end": { "line": 35, "column": 22 } } ] ``` Fixes #71 [1]: https://github.com/yahoo/react-intl/blob/25f3f64d86ac86281157117b5bdb9fa30d1d615f/examples/translations/src/client/components/app.js
I see that the change has been published. Thanks a lot! |
Now that this plugin helps me extract the messages I need to translate (and it works great, thanks!), I am trying to generate a list of message-related issues (untranslated messages, etc.) further in my process. This is why I could use an additional "originalLineNumber" field in the extracted JSON data (or maybe "sourceLineNumber", or any other self-explaining name, of course). That information would let me find more quickly where, in the source code, the message is declared. Of course, the original file name would be useful too, but I can guess it from the JSON file path. And since not everybody is interested in the information, it could be made optional (maybe an "includeOriginalLineNumbers" option?).
Do you think it would be both possible and relevant?
A quick look at the plugin source code makes me think that the function storeMessage() could get the information from the property path.node.loc.start.line, when available. But then I may not be aware of some Babel subtleties.
The text was updated successfully, but these errors were encountered: