-
Notifications
You must be signed in to change notification settings - Fork 310
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
Rename translation function alias #428
Conversation
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.
Hi @sngyo - thanks for doing this. My primary comment is regarding constraining this to only the existing _()
functions.
jupyter_server/serverapp.py
Outdated
@@ -1714,17 +1714,17 @@ def shutdown_no_activity(self): | |||
|
|||
seconds_since_active = \ | |||
(utcnow() - self.web_app.last_activity()).total_seconds() | |||
self.log.debug(_i18n("No activity for %d seconds.", | |||
seconds_since_active)) | |||
self.log.debug("No activity for %d seconds.", |
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 don't think we should be introducing new localized strings in this exercise. Only those statements wrapped in _()
should be replaced with _i18n()
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.
Sorry, this comment is on the wrong line now and it looks like things were reverted, but I think the point is still the same - let's not introduce new strings for localization bundles in this PR. I think there are a few other cases in serverapp.py where this occurred.
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.
Hi @kevin-bates,
thanks for the advice, I'll revert the last two commits later! 😄
--> DONE!
@@ -10,4 +10,4 @@ | |||
# Set up message catalog access | |||
base_dir = os.path.realpath(os.path.join(__file__, '..', '..')) | |||
trans = gettext.translation('notebook', localedir=os.path.join(base_dir, 'notebook/i18n'), fallback=True) | |||
_ = trans.gettext | |||
_i18n = trans.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.
@goanpeca, @Zsailer - do you know if server extensions use this _
alias to wrap localizable strings? If so, we may not want to fully replace it, but define two aliases for now. Since we may not know, it might be best to keep both.
@sngyo - I suspect we'll want to add some kind of commented directive such that the "unused global variable" warning is not emitted. (This is probably another reason why _
was used.)
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.
1. two alias
How do you think introducing a deprecation warning for _()
as below?
import warnings
def _trans_gettext_helper(*args, **kwargs):
warn_msg = "The alias `_()` will be deprecated. Use `_i18n()` instead."
warnings.warn(warn_msg, UserWarning)
return trans.gettext(*args, **kwargs)
_ = _trans_gettext_helper
_i18n = trans.gettext
2. skip unused global variable
I'll look for the method to ignore (skip) the warning for Github CodeScanning. There should be something like this (maybe it will work 😆 ):
_i18n = trans.gettext # noqa: E640
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.
- two alias
I think it makes sense to add a deprecation warning for this. I see you're using UserWarning
- I'm guessing due to the limitations for DeprecationWarning
. I would suggest using FutureWarning
for this instead since it more closely identifies with the intention. (We also used this warning level recently in jupyter_client.)
- skip unused global variable
I had linting on my mind when I made this suggestion. I'm not immediately finding linting-style directives for codeQL, so this probably isn't a big deal since codeQL is still succeeding. Sorry for the misdirection.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #428 +/- ##
==========================================
+ Coverage 77.46% 77.48% +0.02%
==========================================
Files 105 105
Lines 8936 8942 +6
Branches 956 956
==========================================
+ Hits 6922 6929 +7
+ Misses 1677 1676 -1
Partials 337 337 ☔ View full report in Codecov by Sentry. |
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 looks good - thank you @sngyo. (I'm assuming this is no longer WIP, but please let us know if that's not the case.)
@kevin-bates Thank you for the review and advice! It's ready to be merged 😄 |
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.
LGTM! Thanks, @sngyo.
Thanks @sngyo - this is helpful! |
Corresponds to #424
In this project,
_
is used as an alias fortrans.gettext
although_
is commonly used as a placeholder for ignored variables or loop variables in Python.In this PR, I'm trying to rename
_
to_i18n
as discussed in #424, it would be clearer and more useful to avoid conflicts between these two uses.P.S.
This is the first time for me to make a contribution, so I would appreciate it if you could kindly point out any inadequacies/advice 😉
TODO
CONTRIBUTING.rst
since the link is outdated.there are bunch of strings which are not given to_i18n
in serverapp.py