Skip to content

[material_ui, cupertino_ui] Localizations#12119

Open
justinmc wants to merge 309 commits into
flutter:mainfrom
justinmc:flutter_localizations
Open

[material_ui, cupertino_ui] Localizations#12119
justinmc wants to merge 309 commits into
flutter:mainfrom
justinmc:flutter_localizations

Conversation

@justinmc

@justinmc justinmc commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This PR attempts to solve the flutter_localizations problem for material_ui and cupertino_ui. The crux of the problem is that apps that import flutter_localizations were getting a version of GlobalMaterialLocalizations that uses flutter/flutter's MaterialLocalizations instead of the one in material_ui (and the same thing for Cupertino). This PR moves these classes into material_ui and cupertino_ui, while keeping other localization code inside flutter_localizations.

How this PR was created

Similar to #11888, this PR copies history from flutter/flutter. All commits are preserved as-is, plus one final commit from me that is a squash of all of my work on this PR. This PR should be landed as a merge without squash.

git filter-repo --path-glob "packages/flutter_localizations/lib/src/l10n/cupertino_*.arb" --path packages/flutter_localizations/lib/src/l10n/generated_cupertino_localizations.dart --path packages/flutter_localizations/lib/src/cupertino_localizations.dart --path packages/flutter_localizations/test/cupertino/ --path-glob "packages/flutter_localizations/lib/src/l10n/material_*.arb" --path packages/flutter_localizations/lib/src/l10n/generated_material_localizations.dart --path packages/flutter_localizations/lib/src/material_localizations.dart --path packages/flutter_localizations/test/material --path packages/flutter_localizations/test/test_utils.dart --path dev/tools/localization/gen_cupertino_localizations.dart --path dev/tools/localization/gen_material_localizations.dart --path dev/tools/localization/language_subtag_registry.dart --path dev/tools/localization/localizations_utils.dart --path dev/tools/localization/localizations_validator.dart --path dev/tools/localization/bin/encode_kn_arb_files.dart --path dev/tools/localization/bin/gen_localizations.dart --path dev/tools/localization/bin/gen_missing_localizations.dart
cd ../packages
git remote add source-origin ../flutter
git fetch source-origin
git merge source-origin/master --allow-unrelated-histories

Before

As described in flutter/flutter#188757, a typical localized app like the following would encounter runtime type errors:

import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:material_ui/material_ui.dart';

...

localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
  GlobalCupertinoLocalizations.delegate,
  GlobalMaterialLocalizations.delegate,
  GlobalWidgetsLocalizations.delegate,
],

After

import 'package:material_ui/material_ui.dart';

...

localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
   ...GlobalMaterialLocalizations.delegates,
],

Open Questions

  • I put the l10n folder in side of <material_ui or cupertino_ui>/lib/l10n because that's what the docs said. Should it be in src/?
    • Yes, I've moved it to src/.
  • I put the generation scripts inside of packages/material_ui/tools/l10n. Is there a better spot? Is it ok that cupertino_ui has to use a script inside of material_ui? The reason why I didn't split the scripts in two is that there would be large amounts of code duplication. I have moved it to the root of the repo at /script/l10n

TODOs

Resources

Fixes flutter/flutter#188757

Hans Muller and others added 30 commits October 16, 2018 14:57
* Make progress indicators accessible
* add missing entry to material_mr.arb
…nd generate one for cupertino english and french (#29824)
@justinmc justinmc added the CICD Run CI/CD label Jul 10, 2026
@justinmc

justinmc commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

@elliette Good catch, when I tested this I didn't use GlobalCupertinoLocalizations. I think the best way to solve this is the following:

import 'package:material_ui/material_ui.dart';
// No flutter_localizations needed.

...

localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
  ...GlobalMaterialLocalizations.delegates,
  // No GlobalWidgetsLocalizations needed, because it's included in the above line.
],

I'm open to other recommendations but I'll update the description up top with this for now.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 10, 2026
@justinmc

Copy link
Copy Markdown
Contributor Author

We should make sure that we update https://flutter.dev/to/internationalization to reflect this as we prepare to ship.

I've added this to my checklist doc and my comms doc.

So in flutter_localizations, will we deprecate the material and cupertino related bits and eventually remove?

Yes, I've added this to my checklist doc as well.

@justinmc justinmc added the CICD Run CI/CD label Jul 10, 2026

@QuncCccccc QuncCccccc left a comment

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.

I did another round of review and verified that we are able to add new strings to both MaterialLocalizations and CupertinoLocalizations, after fixing the comments below:) This is the test PR I created only for verification justinmc#2

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.

Since we update the script localization, we should also update the first paragraph from

// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use:
// dart packages/material_ui/script/l10n/bin/gen_localizations.dart --overwrite

to

// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use:
// dart script/l10n/bin/gen_localizations.dart --overwrite

Sorry, the file shows Diff is too big to render, so I cannot directly suggest changes:).


// This file has been automatically generated. Please do not edit it manually.
// To regenerate the file, use:
// dart packages/material_ui/script/l10n/bin/gen_localizations.dart --overwrite

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.

Suggested change
// dart packages/material_ui/script/l10n/bin/gen_localizations.dart --overwrite
// dart script/l10n/bin/gen_localizations.dart --overwrite

//
// These classes are constructed by the [getCupertinoTranslation] method at the
// bottom of this file, and used by the [_GlobalCupertinoLocalizationsDelegate.load]
// method defined in `cupertino_ui/lib/src/global_cupertino_localizations.dart`.

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.

Suggested change
// method defined in `cupertino_ui/lib/src/global_cupertino_localizations.dart`.
// method defined in `packages/cupertino_ui/lib/src/global_cupertino_localizations.dart`.

When we run gen_localizations.dart, the header will be updated to above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Indeed it worked 👍

Comment thread script/l10n/bin/gen_localizations.dart Outdated
generateConstructorForCountrySubClass ??= generateConstructor;
final output = StringBuffer();
output.writeln(
generateHeader('dart packages/material_ui/script/l10n/bin/gen_localizations.dart --overwrite'),

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.

Suggested change
generateHeader('dart packages/material_ui/script/l10n/bin/gen_localizations.dart --overwrite'),
generateHeader('dart script/l10n/bin/gen_localizations.dart --overwrite'),

The `.arb` files in this directory contain localized values (primarily strings)
used by the Material library. The `generated_material_localizations.dart` file
combines all of the localizations into a single Map that is linked with the rest
of flutter_localizations package.

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.

Suggested change
of flutter_localizations package.
of material_ui package.

The `.arb` files in this directory contain localized values (primarily strings)
used by the Cupertino library. The `generated_cupertino_localizations.dart` file
combines all of the localizations into a single Map that is linked with the rest
of flutter_localizations package.

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.

Suggested change
of flutter_localizations package.
of cupertino_ui package.

2. Update the .arb files. Modify the out-of-date English strings in
`lib/src/l10n/cupertino_en.arb`.

You also need to re-generate `lib/src/l10n/generated_material_localizations.dart` by running:

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.

Suggested change
You also need to re-generate `lib/src/l10n/generated_material_localizations.dart` by running:
You also need to re-generate `lib/src/l10n/generated_cupertino_localizations.dart` by running:

@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 13, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 13, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 13, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 13, 2026
@justinmc

Copy link
Copy Markdown
Contributor Author

@QuncCccccc Thanks again for catching all of these that I missed! And thanks for testing adding a new string. I tried the same thing locally and got similarly good results.

Since we update the script localization, we should also update the first paragraph

Good call, I've updated the generation script to reflect this in d9f5dd6 and then regenerated those files in ff4a5ba. Bonus verification that the generation script works 👍 .

@justinmc justinmc requested a review from QuncCccccc July 13, 2026 18:12

@Piinks Piinks left a comment

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.

LGTM

@chunhtai chunhtai left a comment

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.

Code LGTM, left some comment on readme, don't want to block the merge so feel free to ignore them or address them as follow up


You also need to re-generate `lib/src/l10n/generated_cupertino_localizations.dart` by running:
```
dart script/l10n/bin/gen_localizations.dart --overwrite

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.

I think we should mention where should one run the script since this will affect which pubspec.yaml will be use

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. The script also enforces that it's run from the repo root.

You can see what that script would generate by running:

```dart
dart script/l10n/bin/gen_localizations.dart

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.

same

Actually update the generated files with:

```dart
dart script/l10n/bin/gen_localizations.dart --overwrite

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.

here as well

The `CupertinoLocalizations` class implementation uses these to lookup localized
resource values.

The gen_localizations script must be run by hand after .arb files have

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 should probably be in the readme of the script directory

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added this there along with brief sections about each script.

Finally you need to re-generate
lib/src/l10n/generated_material_localizations.dart by running:
```
dart script/l10n/bin/gen_localizations.dart --overwrite

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.

same for material readme

Comment thread script/l10n/README.md Outdated
This directory contains scripts for generating Dart localizations. Currently it
is only used by material_ui and cupertino_ui.

Originally, this code was located in flutter/flutter at

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.

Should we mention this at all in this readme? This is good context during this transition, but not something necessary to know in order to use or work on this script

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call, I've reworded and moved this section.

Comment thread script/l10n/README.md

For instructions on how to use these scripts to generate localizations for
material_ui and cupertino_ui, see
[packages/material_ui/lib/src/l10n/README.md](https://github.com/flutter/packages/blob/main/packages/material_ui/lib/src/l10n/README.md)

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.

I wonder if this should be another way around to put the instruction here and let both readme link to this doc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This one I'll defer until after this PR while we're still feeling this out. I agree there's a lot of duplication here and order that could be improved. flutter/flutter#189450

@justinmc

Copy link
Copy Markdown
Contributor Author

As soon as CI passes here, I will squash my commits to prepare the PR to land.

@QuncCccccc QuncCccccc left a comment

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.

LGTM! Thank you!

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you! LGTM

// Run this program from the root of the git repository.
//
// ```
// dart dev/tools/localization/bin/gen_missing_localizations.dart

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This path is no longer correct.

Comment thread script/l10n/.gitignore Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's fine if you want to leave this, but we have a repo-level ignore for .dart_tool already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks I'll remove it, it was generated by dart create.

Comment thread script/l10n/pubspec.yaml Outdated
name: l10n
description: Generates localizations for material_ui and cupertino_ui.
version: 1.0.0
# repository: https://github.com/flutter/packages/tree/main/script/l10n

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You should be able to omit this is this is just local tooling.

Also, presumably you want publish_to: none in this file.

Comment thread script/l10n/pubspec.yaml Outdated
path: ^1.9.0

dev_dependencies:
lints: ^6.0.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this actually used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Another one from dart create, I'll remove it.

intl: any
intl: ^0.20.2
# This is not unpinned currently.
# See https://github.com/flutter/flutter/issues/185017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

FWIW, this doesn't really clarify what the plan is for this package; that issue just discusses it in the context of flutter/flutter. I would assume that this would just become a standard unpinned ^ carat dependency in the context of a published package.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've started a conversation in the issue about what to do about this, thanks for flagging.

return found;
});
if (shouldWrite) {
// ignore: avoid_print

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Optional, but I would remove these and just do an ignore for the whole file; that's how we generally handle things in bin or tool directories here.

flutter/flutter's flutter_localization package that relates to
material_ui and cupertino_ui. Moves the code to the right place, makes
sure it operates on the correct directories and works correctly and
passes CI, and rewords docs and READMEs to reflect the changes.

 * Creates a *_ui/lib/src/l10n directory.
 * Moves dart classes into material_ui and cupertino_ui.
 * Moves the arb files into material_ui and cupertino_ui.
 * Moves the *_ui l10n tests and makes sure they pass.
 * Moves the localization scripts to script/l10n and updates them to
   work in their new location.
 * Moves READMEs and rewords them, and creates a new README for the
   scripts.
 * Updates the license headers to match flutter/packages.
 * Removed some tests that shouldn't come in until flutter/flutter#188473 is ported to flutter/packages.
 * Skips some tests that failed on web that were previously not run on
   the web at all.
@justinmc justinmc force-pushed the flutter_localizations branch from d8a1442 to 43a4d61 Compare July 14, 2026 18:22
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 14, 2026
@Piinks

Piinks commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

I think I'll need to push some buttons in the admin settings to land this with @stuartmorgan-g like we did for the main decoupling PR. I am standing by, let me know when you would like to do so. :)

@justinmc

Copy link
Copy Markdown
Contributor Author

Go for it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: cupertino_ui p: material_ui triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[decoupling] Using flutter_localizations with material_ui/cupertino_ui