From be724796aac64b2bb1413885d33116d365281aa1 Mon Sep 17 00:00:00 2001 From: Andrew Kolos Date: Mon, 3 Jun 2024 11:08:19 -0700 Subject: [PATCH] update generated localized message files in the stocks test app (#148741) Fixes https://github.com/flutter/flutter/issues/149386. Fixes https://github.com/flutter/flutter/issues/106150. The stocks test app includes Dart files containing localized messages generated by `package:flutter_localizations`. However, these files appear to have become out of date. Running `pub get` in the project will regenerate these files and generate a diff, which can be annoying when working on the repo. This PR generates the files. ~~It also updates the templates for these files to be compliant with flutter/flutter repo lint rules, including `noop_primitive_operations` and `use_super_parameters`.~~ It also adds `// ignore_for_file: type=lint` to these files to disable linting for these files. This avoids issues like https://github.com/flutter/flutter/issues/106150 and [this](https://github.com/flutter/flutter/pull/148741#issuecomment-2141161753). --- .../test_apps/stocks/lib/i18n/regenerate.md | 2 +- .../stocks/lib/i18n/stock_strings.dart | 30 ++++++++++--------- .../stocks/lib/i18n/stock_strings_en.dart | 5 ++-- .../stocks/lib/i18n/stock_strings_es.dart | 5 ++-- .../src/localizations/gen_l10n_templates.dart | 4 +++ .../generate_localizations_test.dart | 6 ++++ 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md b/dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md index 83b7e7b5d160..54abe40f2f2e 100644 --- a/dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md +++ b/dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md @@ -1,6 +1,6 @@ # Regenerating the i18n files -The files in this directory are used to generate `stock_strings.dart`, +The arb files in this directory are used to generate `stock_strings.dart`, which contains the `StockStrings` class. This localizations class is used by the stocks application to look up localized message strings. The stocks app uses the [Dart `intl` package](https://github.com/dart-lang/intl). diff --git a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart index d82befae49b2..853e597bb9e9 100644 --- a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart +++ b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart @@ -14,12 +14,14 @@ import 'package:intl/intl.dart' as intl; import 'stock_strings_en.dart'; import 'stock_strings_es.dart'; -/// Callers can lookup localized strings with an instance of StockStrings returned -/// by `StockStrings.of(context)`. +// ignore_for_file: type=lint + +/// Callers can lookup localized strings with an instance of StockStrings +/// returned by `StockStrings.of(context)`. /// /// Applications need to include `StockStrings.delegate()` in their app's -/// localizationDelegates list, and the locales they support in the app's -/// supportedLocales list. For example: +/// `localizationDelegates` list, and the locales they support in the app's +/// `supportedLocales` list. For example: /// /// ```dart /// import 'i18n/stock_strings.dart'; @@ -43,7 +45,7 @@ import 'stock_strings_es.dart'; /// sdk: flutter /// intl: any # Use the pinned version from flutter_localizations /// -/// # rest of dependencies +/// # Rest of dependencies /// ``` /// /// ## iOS Applications @@ -66,7 +68,7 @@ import 'stock_strings_es.dart'; /// be consistent with the languages listed in the StockStrings.supportedLocales /// property. abstract class StockStrings { - StockStrings(String locale) : localeName = intl.Intl.canonicalizedLocale(locale); + StockStrings(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString()); final String localeName; @@ -97,7 +99,7 @@ abstract class StockStrings { static const List supportedLocales = [ Locale('en'), Locale('en', 'US'), - Locale('es'), + Locale('es') ]; /// Title for the Stocks application @@ -124,7 +126,7 @@ class _StockStringsDelegate extends LocalizationsDelegate { @override Future load(Locale locale) { - return SynchronousFuture(_lookupStockStrings(locale)); + return SynchronousFuture(lookupStockStrings(locale)); } @override @@ -134,16 +136,16 @@ class _StockStringsDelegate extends LocalizationsDelegate { bool shouldReload(_StockStringsDelegate old) => false; } -StockStrings _lookupStockStrings(Locale locale) { +StockStrings lookupStockStrings(Locale locale) { // Lookup logic when language+country codes are specified. switch (locale.languageCode) { case 'en': { - switch (locale.countryCode) { - case 'US': return StockStringsEnUs(); - } - break; - } + switch (locale.countryCode) { + case 'US': return StockStringsEnUs(); + } + break; + } } // Lookup logic when only language code is specified. diff --git a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_en.dart b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_en.dart index 51e98b400229..7865abd9a29f 100644 --- a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_en.dart +++ b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_en.dart @@ -5,12 +5,13 @@ // THE FOLLOWING FILES WERE GENERATED BY `flutter gen-l10n`. - import 'stock_strings.dart'; +// ignore_for_file: type=lint + /// The translations for English (`en`). class StockStringsEn extends StockStrings { - StockStringsEn([super.locale = 'en']); + StockStringsEn([String locale = 'en']) : super(locale); @override String get title => 'Stocks'; diff --git a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_es.dart b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_es.dart index 675a57e205dc..c49643aca0ca 100644 --- a/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_es.dart +++ b/dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_es.dart @@ -5,12 +5,13 @@ // THE FOLLOWING FILES WERE GENERATED BY `flutter gen-l10n`. - import 'stock_strings.dart'; +// ignore_for_file: type=lint + /// The translations for Spanish Castilian (`es`). class StockStringsEs extends StockStrings { - StockStringsEs([super.locale = 'es']); + StockStringsEs([String locale = 'es']) : super(locale); @override String get title => 'Acciones'; diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart index 068ab3611c81..db87cecf1407 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart @@ -18,6 +18,8 @@ import 'package:intl/intl.dart' as intl; @(messageClassImports) +// ignore_for_file: type=lint + /// Callers can lookup localized strings with an instance of @(class) /// returned by `@(class).of(context)`. /// @@ -171,6 +173,8 @@ const String dateVariableTemplate = ''' const String classFileTemplate = ''' @(header)@(requiresIntlImport)import '@(fileName)'; +// ignore_for_file: type=lint + /// The translations for @(language) (`@(localeName)`). class @(class) extends @(baseClass) { @(class)([String locale = '@(localeName)']) : super(locale); diff --git a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart index 5d3742c7ddbc..c3c28b362fa6 100644 --- a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart @@ -794,6 +794,8 @@ HEADER import 'bar.dart'; +// ignore_for_file: type=lint + /// The translations for English (`en`). class FooEn extends Foo { FooEn([String locale = 'en']) : super(locale); @@ -894,6 +896,8 @@ flutter:\r expect(fs.file('/lib/l10n/app_localizations_en.dart').readAsStringSync(), ''' import 'app_localizations.dart'; +// ignore_for_file: type=lint + /// The translations for English (`en`). class AppLocalizationsEn extends AppLocalizations { AppLocalizationsEn([String locale = 'en']) : super(locale); @@ -925,6 +929,8 @@ HEADER import 'app_localizations.dart'; +// ignore_for_file: type=lint + /// The translations for English (`en`). class AppLocalizationsEn extends AppLocalizations { AppLocalizationsEn([String locale = 'en']) : super(locale);