-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
[i18n] Load "en" translations parallely #3102
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.
I have some questions about this code for @rajatvijay.
@pavish I'd like you review this as well since you understand this area of the app much better than me.
Also, I haven't tried running this in prod mode. I've been holding off on doing that while reviewing these PRs in hopes that someone would do it once all the i18n changes are in. But this work definitely needs some testing in prod mode by someone at some point. I'm not not sure when the best time to do that is, given how much is still in flux with the i18n work.
mathesar_ui/src/i18n/i18n-load.ts
Outdated
@@ -30,3 +30,11 @@ export async function loadLocaleAsync(locale: Locales): Promise<void> { | |||
updateTranslationsDictionary(locale, await importLocaleAsync(locale)); | |||
loadFormatters(locale); | |||
} | |||
|
|||
export function loadTranslationsIntoMemory( |
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.
Can this function be named loadTranslations
instead? The name loadTranslationsIntoMemory
throws me off a bit because it's in the same file as other functions which seem to be also loading things into memory but are not named in a similar manner.
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.
mathesar_ui/src/App.svelte
Outdated
const checkTranslationsInterval = setInterval(() => { | ||
// eslint-disable-next-line prefer-destructuring | ||
const translations: | ||
| { lang: Locales; translationStrings: string } | ||
| undefined = | ||
// @ts-expect-error added by index.html | ||
window.translations; | ||
if (translations) { | ||
loadTranslationsIntoMemory( | ||
translations.lang, | ||
JSON.parse(translations.translationStrings), | ||
); | ||
setLocale(translations.lang); | ||
isTranslationsLoaded = true; | ||
return true; | ||
}); | ||
})(); | ||
clearInterval(checkTranslationsInterval); | ||
} | ||
}, 100); |
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 approach seems strange to me. If I understand correctly, in index.html
we're importing the translation data and sticking it on window
. Then here we are looking at window
every 100ms to see if it has loaded. This seems really hacky. Why can't we do await import
and let vite sort it out?
I wouldn't expect us to need to deal with window
. But if we absolutely do, then I'd prefer to use a .d.ts
file to provide our own typings for window.translation
instead of the @ts-expect-error
approach 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.
If we do await import
vite will download App.svelte
first & then start the download for the translations. The code here enables the parallel download for both of the things.
I have added the translations
object in global.d.ts
855da7b
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.
With the latest set of changes, this approach of checking the data with setInterval is no longer used.
@rajatvijay Could you please resolve the conflicts in this PR? |
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.
@rajatvijay I've added my review comments.
I'm not sure if you've tested the PR thoroughly before raising it. The changes do not work. Please ensure that you've tested any new changes in both development and production modes.
}; | ||
import { loadTranslations } from './i18n/i18n-load'; | ||
|
||
let isTranslationsLoaded = false; |
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.
from @seancolsen - adding a comment here explaining "why this approach?" since this approach is weird.
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.
Added
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.
@rajatvijay and I had a review call and these were the changes that were discussed.
- Move the window.translations initialization into the translation ts files.
- Remove promise from index.html and change it to <script type="module" src={src}>.
- Add legacy support back.
- Don't stringify translation strings.
- Use "Mathesar" instead of "mathesar".
- Remove '.js' extension in all i18n import statements.
(Optional):
- Namespace translation files if possible.
- Move objects that are only used to store translations from 'i18n-util' into a separate file.
- Use a single point of access to set and retrieve locale store values.
…ad-en-translations-parallely
…ad-en-translations-parallely
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.
@rajatvijay Looks good to me, approved! Thanks for addressing all my concerns.
@seancolsen Based on your comment here, I assume you might be interested in taking a look at this PR. I'm holding off merging for you and @rajatvijay to sort it out.
Relates #2927
Technical details
This PR does the following things -
en
in the backendLoom
https://www.loom.com/share/9689a91822094772851277d61bd376c8
Checklist
Update index.md
).develop
branch of the repositoryvisible errors.
Developer Certificate of Origin
Developer Certificate of Origin