[material_ui, cupertino_ui] Localizations#12119
Conversation
Updating Flutter fork
…nd to make room for cupertino (#29644)
…e class with date time formatting (#29767)
…n the instructions (#30527)
…t of gen_localizations.dart (#29822)
Updating flutter fork
…nd generate one for cupertino english and french (#29824)
Updating flutter fork
…orted languages (#31644)" (#32470) This reverts commit 5c3c680.
…ted languages (#32513)
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
|
I'm opening this PR to review with two caveats:
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 001: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 |
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
packages/.ci/targets/analyze.yaml
Lines 5 to 8 in 6fa759e
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Just double checking, the script lives in material_ui, not cupertino_ui?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
| @@ -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 | |||
Sorry, this comment posted as incomplete. Updated. |
QuncCccccc
left a comment
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
| // 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); |
There was a problem hiding this comment.
| 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: |
There was a problem hiding this comment.
Should this be
| 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: |
There was a problem hiding this comment.
| 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: |
There was a problem hiding this comment.
| 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`. |
There was a problem hiding this comment.
| // 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'; |
There was a problem hiding this comment.
The generated_material_localizations.dart shows the header should be
| 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'; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
| // `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`. |
There was a problem hiding this comment.
| // method defined in `flutter_localizations/lib/src/material_localizations.dart`. | |
| // method defined in `material_ui/lib/src/global_material_localizations.dart`. |
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.
Before
As described in flutter/flutter#188757, a typical localized app like the following would encounter runtime type errors:
After
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/?TODOs
Update l10n README files.Resources
Fixes flutter/flutter#188757