-
Notifications
You must be signed in to change notification settings - Fork 935
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
base: main
Are you sure you want to change the base?
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 |
Co-authored-by: Dustin Ingram <di@users.noreply.github.com>
Not to completely derail this direction, but had you looked at https://www.npmjs.com/package/@zainulbr/i18n-webpack-plugin or such at all? We currently use Webpack to generate bundles, so it'd be cool if we could have those localized and served once, instead of on demand for each page. |
@miketheman commit 8fb15dd is a draft of an alternate approach that generates a It's a draft (I couldn't get gettext.js to import / require properly). Comparison: server-side approach:
cons:
client-side approach:
cons:
|
I had a look at that webpack plugin, and some other approaches. |
@cofiem Taking another look here at the alternative approach from commit 8fb15dd
If the answer to all of these "yes", it seems like this approach would be better for now. |
Alright, I'll try to explain what I've done. I attempted an approach similar to https://www.npmjs.com/package/@zainulbr/i18n-webpack-plugin There is a problem with So, the development process with these changes:
These are the benefits of this approach:
|
Removes gettext.js.
Fix timeago.js
This PR enables translating strings in javascript.
It demonstrates the js translation in use by applying it to the
timeago.js
js util.Note that the js util
fetch-gettext.js
returns a promise which is the Fetch API promise.Please consider:
make translations
output?Changes:
In progress:
make translations
output from js stringsIssues:
Relates to issues: