Skip to content

[material_ui, cupertino_ui] Localizations#12119

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

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

Tim Sneath and others added 30 commits April 5, 2019 11:39
…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
Updates localizations to match what is now generated. It's unclear what caused the change: it didn't happen because of a flutter PR change, so we're still looking for where the source of the non-determinism is.  In the meantime, this will fix the build.
* Sort Localization generation output

- When creating locales that were assumed from existing locales, the
file that is used is non-deterministic. This adds a sort to the iterator
to ensure that the same existing locale is used to generate the assumed
locale
- When generating material, cupertino and date localizations, the generated getters were not sorted. This
introduces an alphabetic sort

* remove main.dart.snapshot
No code changes, just comments: I spell-checked all the comments in the repo.
* Update project.pbxproj files to say Flutter rather than Chromium

Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.

* Update the copyright notice checker to require a standard notice on all files

* Update copyrights on Dart files. (This was a mechanical commit.)

* Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.

Some were already marked "The Flutter Authors", not clear why. Their
dates have been normalized. Some were missing the blank line after the
license. Some were randomly different in trivial ways for no apparent
reason (e.g. missing the trailing period).

* Clean up the copyrights in non-Dart files. (Manual edits.)

Also, make sure templates don't have copyrights.

* Fix some more ORGANIZATIONNAMEs
@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`.

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.

Thank you so much for the attention to detail in your review! I missed so many of these out of date paths and stuff that would have confused our users.

@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
@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
@github-actions github-actions Bot removed the CICD Run CI/CD label Jul 10, 2026
@elliette

Copy link
Copy Markdown
Member

Note: To get this to work with the demo app in flutter/flutter#188757, I had to do the following:

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

(as noted in PR description)

but also, I had to change:

MaterialApp(
      locale: const Locale('es'),
      supportedLocales: const <Locale>[Locale('en'), Locale('es')],
      localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      home: const HomeScreen(),
)

to

MaterialApp(
      locale: const Locale('es'),
      supportedLocales: const <Locale>[Locale('en'), Locale('es')],
      localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
        ...GlobalMaterialLocalizations.delegates,  <-- use delegateS
        GlobalWidgetsLocalizations.delegate,
              <-- remove Cupertino localizations
      ],
      home: const HomeScreen(),
)

I originally tried the following, but got this runtime error:

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

MaterialApp(
      locale: const Locale('es'),
      supportedLocales: const <Locale>[Locale('en'), Locale('es')],
      localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      home: const HomeScreen(),
    )
Warning: This application's locale, es, is not supported by all of its localization delegates.

• A CupertinoLocalizations delegate that supports the es locale was not found.

If the application is built using GlobalMaterialLocalizations.delegate, consider using GlobalMaterialLocalizations.delegates (plural) instead, as that will automatically declare the appropriate Cupertino localizations.

The declared supported locales for this app are: en, es

See https://flutter.dev/to/internationalization/ for more information about configuring an app's locale, supportedLocales, and localizationsDelegates parameters.

Comment thread packages/material_ui/pubspec.yaml Outdated
@@ -21,17 +21,23 @@ dependencies:
sdk: flutter
# This is not unpinned currently.
# See https://github.com/flutter/flutter/issues/185017

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.

Comment should be above material_color_utilities


// Examples can assume:
// import 'package:flutter_localizations/flutter_localizations.dart';
// import 'package:flutter/material.dart';

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.

Should this comment be updated?

Here as well:

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


/// Only used to generate localization strings for the Kannada locale ('kn') because
/// some of the localized strings contain characters that can crash Emacs on Linux.
/// See packages/flutter_localizations/lib/src/l10n/README for more information.

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.

Maybe: "See packages/flutter_localizations/lib/src/l10n/README in the Flutter SDK for more information" ?

// replaced by JSON escapes. This is done because some of those strings
// contain characters that can crash Emacs on Linux. There is more information
// here: https://github.com/flutter/flutter/issues/36704 and in the README
// in flutter_localizations/packages/lib/src/l10n.

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.

Ditto here - maybe add "in the Flutter SDK"

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