-
Notifications
You must be signed in to change notification settings - Fork 985
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
Allow translating from javascript files #15612
Conversation
Very cool! I like this approach a lot, I think this will definitely work. One thing I'm wondering: since we probably won't have a ton of JS translations, would it make sense to load them all for a given locale in a bundle via a single request, as opposed to making |
I'm not sure I understand this. I found a way to use the server-side rendering of translations because:
If you're concerned about the server load or frequency of requests, the browser cache seems to work well, and there's likely some additional caching to be done in the server-side view that could reduce the need to execute the Please let me know if I've misunderstood what you're asking. |
I managed to get the plurals extracted. It looks like python-babel expects particular function names. TODO:
Question:
|
Provide two functions for gettext so IDe highlighting is useful.
Yes, I was thinking about balancing the number of requests with the size of the requests. It's probably an over-optimization though, our CDN will cache these responses by default so it's not the load on our backend that I was concerned with, just the number of requests the user's browser would have to make after the page has loaded. I think it's fine to move forward as-is, just wanted to think through it a bit.
By default, we cache all requests, but strip all URL parameters when caching a given view (with some exceptions). We can add an exception for this view. This happens here: |
The only remaining question is what @di was asking - is the number of requests made by the browser a problem? Some example screenshots of the js translations in use. |
Test errors:
This one could be fixed by adding - msg += " " + " ".join(results["feedback"]["suggestions"])
+ msg = str(msg) + " " + " ".join(results["feedback"]["suggestions"])
I'm not sure how to fix this error. Other form tests seem to be able to set |
Added comment to explain what the pattern is checking.
This is important as these values will be embedded into the messages-access.js file.
…ture/translation-js
…ture/translation-js
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
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
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
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'm +1 to these changes, and will add a few commits that fix minor nits that have crept in since. I plan to merge tomorrow morning.
Looks like this is causing build failures: /~https://github.com/pypi/warehouse/actions/runs/12811292443/job/35720280486?pr=17373 |
I think this should resolve it: #17424 |
removed 28 packages, and audited 1020 packages in 904ms Final direct usage removed in pypi#15612 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
* chore(ci): update node version Sync with `Dockerfile` Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): npm update added 60 packages, removed 171 packages, changed 233 packages, and audited 1082 packages in 22s Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): update webpack-cli changed 7 packages, and audited 1082 packages in 1s Refs: /~https://github.com/webpack/webpack-cli/blob/5a6a70b8dfe38e147ee158018dd154e49a5a0c0d/CHANGELOG.md#601-2024-12-20 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): update stylelint-config-standard-scss changed 1 package, and audited 1082 packages in 965ms Refs: /~https://github.com/stylelint-scss/stylelint-config-standard-scss/blob/d0feabca7e43ddcb033f0636ccdeb4ca9b0671ad/CHANGELOG.md#1400 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): update gettext-parser Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): update sharp added 2 packages, removed 38 packages, changed 1 package, and audited 1046 packages in 1s Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): remove glob removed 28 packages, and audited 1020 packages in 904ms Final direct usage removed in #15612 Signed-off-by: Mike Fiedler <miketheman@gmail.com> * chore(deps): update sass-loader Needs an update to the "local" loading path. Refs: https://webpack.js.org/loaders/sass-loader/#resolving-import-and-use-at-rules Signed-off-by: Mike Fiedler <miketheman@gmail.com> --------- Signed-off-by: Mike Fiedler <miketheman@gmail.com> Co-authored-by: Ee Durbin <ewdurbin@gmail.com>
This PR enables translating strings in javascript.
It demonstrates the js translation in use by applying it to the
timeago.js
js util.Edit: added overview of the two mutually-exclusive approaches.
Approach: webpack plugin the generates js message bundles
This is the current state of this PR.
I attempted an approach similar to https://www.npmjs.com/package/@zainulbr/i18n-webpack-plugin
i.e. embed the translations into separate js bundles, one for each language.
Unfortunately, the existing webpack plugins were not suitable (issues with webpack 5 and/or did not work for the warehouse setup).
However, I did manage to create a webpack plugin that does the job (in webpack.plugin.localize.js).
The plugin checks the plural forms and embeds them into the generated js bundles.
So, the development process with these changes:
These are the benefits of this approach:
Approach: request from client to server to get translation for a given message code
A js util
fetch-gettext.js
that requests the translation code returns a promise, which contains the translation text from the server, using the locale set on the server-side.view the changes for this approach.
Changes:
Considerations:
Notes
Relates to issues: