Skip to content
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

Lazy load translations and date-fns, server side support for "Browser Default" language #2380

Merged
merged 7 commits into from Mar 13, 2024

Conversation

matc-pub
Copy link
Contributor

@matc-pub matc-pub commented Feb 28, 2024

Description

Lazy loads i18n translations and date-fns using dynamic imports.

Before

Both scripts are always loaded.

	client.js: 915.51kB (3.29MB)
	48.client.js: 103.53kB (601.55kB) << date-fns

After

For "en-US" only client.js is loaded. "en-GB" and "en-CA" additionally load one date-fns-*client.js, Most languages load one translation-*.client.js and one date-fns-*.client.js. Languages like "pt-BR", for which a specific (pt-BR) and general (pt) translation exists, load two translations and one date-fns.

	client.js: 724.04kB (2.57MB)
	translation-el.client.js 11.64kB (43.67kB) << largest translation
	date-fns-be-tarask-mjs.client.js 3.66kB (13.23kB) << largest date-fns

date-fns are picked to match the language that i18n uses.

Uses the "Accept-Language" header to determine which language to use for server side rendering. This also allows to load translations and date-fns in parallel with client.js.

The language code for "pt-BR" is no longer "pt_BR".

"DOMContentLoaded" (used for Notification permission) started working when only client.js is needed.

Only when no translations and date-fns have to be dynamically loaded
(e.g. for en-US) the NavBar `componentDidMount` is early enough to
listen for "DOMContentLoaded".

Removes one redundant `requestNotificationPermission()` call.
Browsers ask for "pt-BR", but the "interface_language" saved in the
settings dialog asks for "pt_BR". This change will make the settings
dialog ask for "pt-BR" instead of "pt_BR". For users that already (or
still) have "pt_BR" configured, "pt-BR" will be used, but the settings
dialog will present it as unspecified.
Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this also, and everything works well. This late-loading stuff is magic to me, but it appears to work. I'll let @SleeplessOne1917 also take a look.

@SleeplessOne1917 SleeplessOne1917 enabled auto-merge (squash) March 13, 2024 20:38
@SleeplessOne1917 SleeplessOne1917 merged commit e832cd2 into LemmyNet:main Mar 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants