Skip to content

feat(core): Global lazy Intl polyfills and locale-sensitive date formatting#1608

Open
erral wants to merge 7 commits into
masterfrom
fix-global-intl-polyfills
Open

feat(core): Global lazy Intl polyfills and locale-sensitive date formatting#1608
erral wants to merge 7 commits into
masterfrom
fix-global-intl-polyfills

Conversation

@erral

@erral erral commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary

This PR improves date formatting across Plone patterns and introduces a global mechanism for lazily loading polyfills and locale data.

Key Changes

  • Locale-Sensitive Formatting: Updated formatDate in pat-filemanager to respect the Plone site language from <html lang='...'> (normalized for Intl).
  • Lazy Intl Polyfills: Added src/core/intl-loader.js which detects if the browser natively supports the current locale. If not, it lazily fetches the @formatjs/intl-datetimeformat polyfill and specific locale data chunks. This ensures languages like Basque (eu) are correctly supported even in limited environments.
  • Pattern Integration: The polyfill loader is now part of the initialization for pat-filemanager, pat-contentbrowser, and pat-structure.
  • Build Support: Configured Webpack aliases to handle dynamic imports of locale data smoothly, enabling clean builds and efficient chunking.
  • Functional Testing: Added src/core/intl-loader.test.js verifying that missing locales trigger polyfill loading and result in correct language-specific output.

Why?

Previously, date formatting often defaulted to the browser's language, leading to UI inconsistencies in Plone sites with a different language than the user's OS. Furthermore, many browsers lack data for certain languages (like eu), causing formatting to fallback to English or fail. This PR provides a robust, per-language lazy-loading solution that fixes these issues for all patterns with minimal overhead.

@erral erral requested review from MrTango and petschki and removed request for petschki June 17, 2026 13:22
let isRestoringHistory = false;

onMount(() => {
onMount(async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is problematic, because the existing event handler will not be cleaned up with async.

Suggested change
onMount(async () => {
onMount(async () => {
await ensureIntlSupport(getLang());
});
onMount(() => {
contents.load();
function onPopState(event) {
const ctx = event.state?.contextUrl;
if (ctx && ctx !== contents.contextUrl) {
isRestoringHistory = true;
contents.navigateTo(ctx).finally(() => {
isRestoringHistory = false;
});
}
}
window.addEventListener("popstate", onPopState);
return () => window.removeEventListener("popstate", onPopState);
});

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.

2 participants