Skip to content

Conversation

@christopherschroer
Copy link
Contributor

This non-breaking PR splits the single giant locale file found here into individual files for each locale.

Benefits:

  • aligns with locale setups in MUI-X packages
  • easier to quickly identify which locales are supported
  • easier to include only locales that are desired in app bundles
  • easier to dynamically import individual locales

@zannager zannager added the l10n Localization. label Sep 15, 2025
@zannager zannager added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: all components Widespread work has an impact on almost all components. labels Sep 15, 2025
@alexfauquette alexfauquette removed their request for review September 15, 2025 15:12
@alexfauquette
Copy link
Member

The PR looks ok to me. I let core team check this does nto imply a breaking change

@LukasTy From what I remeber you had to do an extra effort to get

easier to include only locales that are desired in app bundles

@@ -0,0 +1,74 @@
import type { Localization } from './utils/LocaleTextApi';

const amET: Localization = {
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it would be simpler to replace these lines with immediate named exports and then use the same re-exporting strategy as in: https://github.com/mui/mui-x/blob/master/packages/x-date-pickers/src/locales/index.ts
WDYT?

Suggested change
const amET: Localization = {
export const amET: Localization = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LukasTy I tried that approach originally, but ESLint got mad. It is currently configured to prefer default export on a file with one export. How should I proceed?

image

Copy link
Member

Choose a reason for hiding this comment

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

You can add an exclusion to disable this rule on packages/mui-material/src/locale/* alongside this:

// Migrated config from packages/api-docs-builder/.eslintrc.js
{
files: ['packages/api-docs-builder/**/*'],
rules: {
'import/prefer-default-export': 'off',
},
},

Unless there is a clear objection from @mui/material-ui? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@LukasTy I have made the recommended changes

Copy link
Member

@LukasTy LukasTy left a comment

Choose a reason for hiding this comment

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

Great work, LGTM. 👍
But I'd still like to see approval from someone more actively maintaining this repo. 🤔

P.S. @christopherschroer could you please run pnpm prettier and commit the fixes? 🙏

Signed-off-by: Lukas Tyla <[email protected]>
@LukasTy LukasTy requested a review from siriwatknp September 16, 2025 13:50
@mui-bot
Copy link

mui-bot commented Sep 16, 2025

Netlify deploy preview

https://deploy-preview-46933--material-ui.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/material 0B(0.00%) 0B(0.00%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against 3d7f4cf

@christopherschroer
Copy link
Contributor Author

Great work, LGTM. 👍 But I'd still like to see approval from someone more actively maintaining this repo. 🤔

P.S. @christopherschroer could you please run pnpm prettier and commit the fixes? 🙏

Done

@siriwatknp
Copy link
Member

siriwatknp commented Sep 18, 2025

easier to include only locales that are desired in app bundles
easier to dynamically import individual locales

Can you elaborate on this?

I think this PR would help the development because a single file is loaded instead of the whole localization but for production it should be the same because of tree-shaking.

For "dynamically import individual locales", I don't think it's possible with dynamic('@mui/material/locale/zhCN') due to the current package json exports is it? cc @Janpot

@christopherschroer
Copy link
Contributor Author

christopherschroer commented Sep 18, 2025

@siriwatknp You are correct about my first claim. However when using a bundle analyzer, having a monolithic locale file makes it harder to determine which locales are being included.

As for the second claim, you can dynamically import locales from MUI by creating individual locale files in your project that simply re-export the applicable locale from MUI and then lazy loading your project's locale files. It's not the slickest way of doing it by far, but it works with how MUI exports everything. It's how I dynamically loaded the locales from MUI-X

@LukasTy
Copy link
Member

LukasTy commented Sep 18, 2025

Thank you for the comments.
Since there are no raised concerns, I'm merging this PR. 👌
Once again, @christopherschroer, your contribution is appreciated. 🙏

@LukasTy LukasTy merged commit c9ca979 into mui:master Sep 18, 2025
18 checks passed
@christopherschroer christopherschroer deleted the split-locales branch September 18, 2025 11:27
@oliviertassinari oliviertassinari changed the title [material-ui][locale] Split locales into separate files [locale] Split locales into separate files Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

l10n Localization. scope: all components Widespread work has an impact on almost all components. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants