-
Notifications
You must be signed in to change notification settings - Fork 35
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
make -k other_keyword append to the defaults #82
Conversation
jsut
commented
Mar 26, 2021
- This is how xgettext works, which is how the docs say it works.
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.
Thank you, this is a great idea. I've left some individual line comments.
On top of that, I think 2 things are still missing:
xgettext
allows to reset the default keywords by passing-k
(without a word). It would be a very good idea to add this behavior in this PR since this provides the easiest upgrade path from the old usage. Otherwise things will break much more for existing users.- It would be great to have tests for the actual differences in keywords passed to the parsers. Now we only test the resulting output. This would require to expose (a part of) the current
getParser
function somehow. I don't know what the best approach is; feedback on this is very much appreciated.
index.js
Outdated
@@ -91,10 +91,9 @@ function xgettext (input, options, cb) { | |||
if (!parsers[name]) { | |||
const Parser = require(`gettext-${name}`); | |||
|
|||
if (Object.keys(keywordSpec).length > 0) { | |||
if (Parser.keywordSpec) { |
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.
If the parser does not offer a default, no keywordSpec
is passed to the parser.
index.js
Outdated
@@ -91,10 +91,9 @@ function xgettext (input, options, cb) { | |||
if (!parsers[name]) { | |||
const Parser = require(`gettext-${name}`); | |||
|
|||
if (Object.keys(keywordSpec).length > 0) { | |||
if (Parser.keywordSpec) { | |||
keywordSpec = Object.assign(keywordSpec, Parser.keywordSpec); |
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 parameter order of Object.assign
always overwrites all custom keywords with their defaults.
test/fixtures/keyword.hbs
Outdated
{{$ "regex escaped keyword"}} |
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.
What's the change 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.
vim being particular about whether their should be a newline at the end of the file. I'll fix it.
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.
Strange, as I don't see a newline at the end of the file in master either. Can it be a different line ending (should be Unix-style)?
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.
there was no newline before.
I haven't looked at the code for this yet, but it seems like another PR to me. There are other issues with -k as well. With gnu xgettext there doesn't have to be (and perhaps cannot be, i haven't tested it) a space after the -k before the identifier. I think another PR that adds this functionality and adds tests for createKeywordSpec could be the right thing to do.
Perhaps add more functionality to keyword-spec.js, a function that will take a bunch of specs and combine them. Then you could test that function directly, and the code currently in this PR gets even simpler. |
I prefer this in the same PR, but separate is fine too. It's just that this functionality is crucial for this PR to move ahead. You don't need to worry about the exact way to specify parameters as that's something that is handled by the optstring parser (yargs). We stick to their format, not xgettext's, in that area.
Yes, this would be great to have. That can definitely be in a separate PR of course. |
@jsut please also run |
done |
@smhg do you need anything else here? |
@jsut there are some minor changes in master. Could you merge them into your branch? I'll check things in the next few days and release this. |
- adding -k with no value will tell the parser not to use the default keywords - adding -k with a value will add a keyword to the list of keywords - add tests
@smhg it's rebased |
@jsut thanks! |
@smhg yup, maybe this afternoon. |
Thank you for your ongoing efforts @jsut! I've had some time to look at the actual changes to the code.
Would you be open to further improve the PR? I'm happy to add comments to the code if you're open to this. |
If you have a cleaner way to implement it @smhg let me know. I just tried to make it work despite it seeming like a pretty pointless thing to implement since running the thing with only a -k will never result in any output other than an empty po file anyway. I dug into how yargs works to try to find a cleaner way to handle this, but it seemed like a dead end. |
- has 2 keys, noDefaults and spec. spec is the old return value, noDefault is a boolean that indicates if they bare keyword was present indicating that the default keywords should not be applied
@smhg this seems cleaner, not loving all the spec.spec, particularly in the tests, but yeah... |
@jsut thank you for your efforts. I don't think this is moving in the right direction. I'd love to offer more timely feedback, but I have to acknowledge I don't have the time for that kind of followup currently. In general:
|
I've added an alternative solution to the v5 branch based on your tests. |
Given your branched changes, i'm not sure if i should be doing anything else here or not.
I'm not sure if you're talking about gnu xgettext here, or this package. In any case, in this branch, both of them support -k/--keyword, in any position in the parameter list on the CLI, with the one caveat that in xgettext-template, if you do -k , or --keyword then yargs will slurp up the filename as the 'keyword'. This is a yargs problem, and i think it's actually impossible to fix without a significant change to yargs, or some serious massaging of what you pass into yargs. Neither of which seem reasonable to me. What does seem reasonable though, is documenting this shortcoming of -k/--keyword. It all goes back to my original complaint about the space after -k. Maybe yargs does handle this, but i'm not that familiar with it and my dive into the docs was not fruitful.
This seems like a reasonable improvement to me. Do you think that the code that does this filtering should live in index.js, or should keyword-spec.js be expanded to have more exports, and one of them is the function that does this? |