Skip to content

[material_ui, cupertino_ui] Localizations#12119

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

[material_ui, cupertino_ui] Localizations#12119
justinmc wants to merge 325 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';

After

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

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.

TODOs

  • Update l10n README files.
  • Squash all of my own commits.

Resources

Fixes flutter/flutter#188757

Hans Muller and others added 30 commits March 12, 2019 16:17
…nd generate one for cupertino english and french (#29824)
…orted languages (#31644)" (#32470)

This reverts commit 5c3c680.
Corects a bnuch of typeos throuhgout teh Fluter codebsae.

Made use of the `misspell` tool:
https://github.com/client9/misspell
* Refresh .arb files

* Refresh localizations
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 7, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 7, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 7, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 7, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 8, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 8, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 8, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 8, 2026
@justinmc

justinmc commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

I'm opening this PR to review with two caveats:

  1. If reviewers are on board, I will squash all of my commits into one before merging, keeping all commits from flutter/flutteras-is.
  2. I am still struggling with two test failures that strangely don't reproduce locally:
01:25 +3072 ~6: /b/s/w/ir/x/w/packages/packages/material_ui/test/l10n/date_time_test.dart: ar is initialized correctly when DateFormat is used
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: '٨:٣٠ م'
  Actual: '8:30 م'
   Which: is different.
          Expected: ٨:٣٠ م
            Actual: 8:30 م
                    ^
           Differ at offset 0
01:28 +3198 ~6 -1: /b/s/w/ir/x/w/packages/packages/material_ui/test/l10n/date_picker_test.dart: CalendarDatePicker shows dates for ar_AR
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: exactly one matching candidate
  Actual: _TextWidgetFinder:<Found 0 widgets with text "سبتمبر ٢٠١٧": []>
   Which: means none were found but one was expected

@justinmc justinmc marked this pull request as ready for review July 8, 2026 21:42
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@justinmc justinmc Jul 8, 2026

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.

@stuartmorgan-g this and related scripts in this directory generate localization files for both material_ui and cupertino_ui. I avoided putting them in the root /scripts directory of this repo because I didn't want to pollute that with something that's specific to only 2 packages. What do you think is the better place for these scripts?

CC @QuncCccccc

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.

If we want the script in material_ui, I think we might want it to be in material_ui/tool/ instead of material_ui/script/. See here

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.

I avoided putting them in the root /scripts directory of this repo because I didn't want to pollute that with something that's specific to only 2 packages.

I think a new package in /script/ is fine from an organizational standpoint. Long term it might make sense to refactor it into a package with the shared parts that lives in /scritpt/, and then a tool in each package's tool/ directory that uses that shared code and has the package-specific parts, but I haven't looked at the details of the code enough to know if that would actually be viable without code duplication.

One slightly annoying thing if you go the /scritpt/ route is that we don't have a generic way that we run standard checks (analyze, format) over script/, so if we add more things there we should really fix that. That doesn't have to block landing there though; you can just add to

- name: analyze repo tools
script: .ci/scripts/analyze_repo_tools.sh
- name: analyze flutter_goldens
script: .ci/scripts/analyze_flutter_goldens.sh
and https://github.com/flutter/packages/blob/main/.ci/targets/repo_checks.yaml#L12-L19 for now and I can file an issue to make it generic (it wasn't an issue when the repo tooling was the only thing in that directory).

The problem was that I copied in a newer change
(flutter/flutter#188473) when I copied in the
localizations stuff. So I got the test changes from that PR, but not the
code change to make the tests pass.

In the future, this PR will come in when we upgrade the SDK for
material_ui and cupertino_ui.
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 9, 2026

@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.

We should make sure that we update https://flutter.dev/to/internationalization to reflect this as we prepare to ship.
So in flutter_localizations, will we deprecate the material and cupertino related bits and eventually remove?

@override
String aboutListTileTitle(String applicationName) => 'About $applicationName';
```
For messages with parameters, do also add the function to `GlobalCupertinoLocalizations` in [`packages/flutter_localizations/lib/src/cupertino_localizations.dart`](https://github.com/flutter/flutter/blob/main/packages/flutter_localizations/lib/src/cupertino_localizations.dart), and add a raw getter as demonstrated below:

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 this be updated to point to cupertino_ui?

Then you need to add new entries for the string to all of the other
language locale files by running:
```
dart packages/material_ui/script/l10n/bin/gen_missing_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.

Just double checking, the script lives in material_ui, not cupertino_ui?

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 I answered my own question. This is a contributor facing tool, not developer, so it does not make sense to dupe it between packages, instead having it live in one place to be run out of.

sdk: flutter
flutter_localizations:
sdk: flutter
intl: any

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.

We'll want to set this to a ^version

@override
String aboutListTileTitle(String applicationName) => 'About $applicationName';
```
For messages with parameters, do also add the function to `GlobalMaterialLocalizations` in [`packages/flutter_localizations/lib/src/material_localizations.dart`](https://github.com/flutter/flutter/blob/main/packages/flutter_localizations/lib/src/material_localizations.dart), and add a raw getter as demonstrated below:

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 for link check

@@ -21,17 +21,23 @@ dependencies:
sdk: flutter
# This is not unpinned currently.
# See https://github.com/flutter/flutter/issues/185017
flutter_localizations:
sdk: flutter
intl: any

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 here re: ^version

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

Piinks commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

We should make sure that we update flutter.dev/to/internationalization to reflect this as we prepare to ship. So in flutter_localizations, will we deprecate the material and cupertino related bits and eventually remove?

Sorry, this comment posted as incomplete. Updated.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 9, 2026
@justinmc justinmc added the CICD Run CI/CD label Jul 9, 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 haven't finished review. Just did a quick look. I'll do another round of review and verify the process to add new strings and export translations from translation console.

//
// 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/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/cupertino_localizations.dart`.
// method defined in `cupertino_ui/lib/src/global_cupertino_localizations.dart`.

String get showMenuTooltip;
```
to the localizations class `CupertinoLocalizations`,
in [`packages/cupertino_ui/lib/src/cupertino_localizations.dart`](https://github.com/flutter/packages/blob/main/packages/cupertino_ui/lib/src/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
in [`packages/cupertino_ui/lib/src/cupertino_localizations.dart`](https://github.com/flutter/packages/blob/main/packages/cupertino_ui/lib/src/cupertino_localizations.dart);
in [`packages/cupertino_ui/lib/src/cupertino_localizations.dart`](https://github.com/flutter/packages/blob/main/packages/cupertino_ui/lib/src/localizations.dart);

@override
String aboutListTileTitle(String applicationName) => 'About $applicationName';
```
For messages with parameters, do also add the function to `GlobalCupertinoLocalizations` in [`packages/flutter_localizations/lib/src/cupertino_localizations.dart`](https://github.com/flutter/flutter/blob/main/packages/flutter_localizations/lib/src/cupertino_localizations.dart), and add a raw getter as demonstrated below:

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 this be

Suggested change
For messages with parameters, do also add the function to `GlobalCupertinoLocalizations` in [`packages/flutter_localizations/lib/src/cupertino_localizations.dart`](https://github.com/flutter/flutter/blob/main/packages/flutter_localizations/lib/src/cupertino_localizations.dart), and add a raw getter as demonstrated below:
For messages with parameters, do also add the function to `GlobalCupertinoLocalizations` in [`packages/cupertino_ui/lib/src/global_cupertino_localizations.dart`](https://github.com/flutter/packages/blob/main/packages/cupertino_ui/lib/src/global_cupertino_localizations.dart), and add a raw getter as demonstrated below:

until they can be translated.

Finally you 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
lib/src/l10n/generated_material_localizations.dart by running:
lib/src/l10n/generated_cupertino_localizations.dart by running:

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

You also need to re-generate `lib/src/l10n/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/localizations.dart` by running:
You also need to re-generate `lib/src/l10n/generated_cupertino_localizations.dart` by running:

//
// These classes are constructed by the [getCupertinoTranslation] method at the
// bottom of this file, and used by the [_GlobalCupertinoLocalizationsDelegate.load]
// method defined in `flutter_localizations/lib/src/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 `flutter_localizations/lib/src/cupertino_localizations.dart`.
// method defined in `cupertino_ui/lib/src/global_cupertino_localizations.dart`.


import 'dart:collection';

import 'package:material_ui/material_ui.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.

The generated_material_localizations.dart shows the header should be

Suggested change
import 'package:material_ui/material_ui.dart';
import 'package:flutter/widgets.dart';

import 'package:material_ui/material_ui.dart';
import 'package:intl/intl.dart' as intl;

import '../material_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.

import '../global_material_localizations.dart';
import '../time.dart';
import '../typography.dart';

import '../material_localizations.dart';

// The classes defined here encode all of the translations found in the
// `flutter_localizations/lib/src/l10n/*.arb` files.

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
// `flutter_localizations/lib/src/l10n/*.arb` files.
// `material_ui/lib/src/l10n/*.arb` files.

//
// These classes are constructed by the [getMaterialTranslation] method at the
// bottom of this file, and used by the [_MaterialLocalizationsDelegate.load]
// method defined in `flutter_localizations/lib/src/material_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 `flutter_localizations/lib/src/material_localizations.dart`.
// method defined in `material_ui/lib/src/global_material_localizations.dart`.

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

Labels

CICD Run CI/CD 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