Skip to content

Commit be72479

Browse files
authored
update generated localized message files in the stocks test app (#148741)
Fixes flutter/flutter#149386. Fixes flutter/flutter#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 flutter/flutter#106150 and [this](flutter/flutter#148741 (comment)).
1 parent 0e7295f commit be72479

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Regenerating the i18n files
22

3-
The files in this directory are used to generate `stock_strings.dart`,
3+
The arb files in this directory are used to generate `stock_strings.dart`,
44
which contains the `StockStrings` class. This localizations class is
55
used by the stocks application to look up localized message strings.
66
The stocks app uses the [Dart `intl` package](https://github.com/dart-lang/intl).

dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart

+16-14
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import 'package:intl/intl.dart' as intl;
1414
import 'stock_strings_en.dart';
1515
import 'stock_strings_es.dart';
1616

17-
/// Callers can lookup localized strings with an instance of StockStrings returned
18-
/// by `StockStrings.of(context)`.
17+
// ignore_for_file: type=lint
18+
19+
/// Callers can lookup localized strings with an instance of StockStrings
20+
/// returned by `StockStrings.of(context)`.
1921
///
2022
/// Applications need to include `StockStrings.delegate()` in their app's
21-
/// localizationDelegates list, and the locales they support in the app's
22-
/// supportedLocales list. For example:
23+
/// `localizationDelegates` list, and the locales they support in the app's
24+
/// `supportedLocales` list. For example:
2325
///
2426
/// ```dart
2527
/// import 'i18n/stock_strings.dart';
@@ -43,7 +45,7 @@ import 'stock_strings_es.dart';
4345
/// sdk: flutter
4446
/// intl: any # Use the pinned version from flutter_localizations
4547
///
46-
/// # rest of dependencies
48+
/// # Rest of dependencies
4749
/// ```
4850
///
4951
/// ## iOS Applications
@@ -66,7 +68,7 @@ import 'stock_strings_es.dart';
6668
/// be consistent with the languages listed in the StockStrings.supportedLocales
6769
/// property.
6870
abstract class StockStrings {
69-
StockStrings(String locale) : localeName = intl.Intl.canonicalizedLocale(locale);
71+
StockStrings(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
7072

7173
final String localeName;
7274

@@ -97,7 +99,7 @@ abstract class StockStrings {
9799
static const List<Locale> supportedLocales = <Locale>[
98100
Locale('en'),
99101
Locale('en', 'US'),
100-
Locale('es'),
102+
Locale('es')
101103
];
102104

103105
/// Title for the Stocks application
@@ -124,7 +126,7 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
124126

125127
@override
126128
Future<StockStrings> load(Locale locale) {
127-
return SynchronousFuture<StockStrings>(_lookupStockStrings(locale));
129+
return SynchronousFuture<StockStrings>(lookupStockStrings(locale));
128130
}
129131

130132
@override
@@ -134,16 +136,16 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
134136
bool shouldReload(_StockStringsDelegate old) => false;
135137
}
136138

137-
StockStrings _lookupStockStrings(Locale locale) {
139+
StockStrings lookupStockStrings(Locale locale) {
138140

139141
// Lookup logic when language+country codes are specified.
140142
switch (locale.languageCode) {
141143
case 'en': {
142-
switch (locale.countryCode) {
143-
case 'US': return StockStringsEnUs();
144-
}
145-
break;
146-
}
144+
switch (locale.countryCode) {
145+
case 'US': return StockStringsEnUs();
146+
}
147+
break;
148+
}
147149
}
148150

149151
// Lookup logic when only language code is specified.

dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_en.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
// THE FOLLOWING FILES WERE GENERATED BY `flutter gen-l10n`.
66

77

8-
98
import 'stock_strings.dart';
109

10+
// ignore_for_file: type=lint
11+
1112
/// The translations for English (`en`).
1213
class StockStringsEn extends StockStrings {
13-
StockStringsEn([super.locale = 'en']);
14+
StockStringsEn([String locale = 'en']) : super(locale);
1415

1516
@override
1617
String get title => 'Stocks';

dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings_es.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
// THE FOLLOWING FILES WERE GENERATED BY `flutter gen-l10n`.
66

77

8-
98
import 'stock_strings.dart';
109

10+
// ignore_for_file: type=lint
11+
1112
/// The translations for Spanish Castilian (`es`).
1213
class StockStringsEs extends StockStrings {
13-
StockStringsEs([super.locale = 'es']);
14+
StockStringsEs([String locale = 'es']) : super(locale);
1415

1516
@override
1617
String get title => 'Acciones';

packages/flutter_tools/lib/src/localizations/gen_l10n_templates.dart

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import 'package:intl/intl.dart' as intl;
1818
1919
@(messageClassImports)
2020
21+
// ignore_for_file: type=lint
22+
2123
/// Callers can lookup localized strings with an instance of @(class)
2224
/// returned by `@(class).of(context)`.
2325
///
@@ -171,6 +173,8 @@ const String dateVariableTemplate = '''
171173
const String classFileTemplate = '''
172174
@(header)@(requiresIntlImport)import '@(fileName)';
173175
176+
// ignore_for_file: type=lint
177+
174178
/// The translations for @(language) (`@(localeName)`).
175179
class @(class) extends @(baseClass) {
176180
@(class)([String locale = '@(localeName)']) : super(locale);

packages/flutter_tools/test/general.shard/generate_localizations_test.dart

+6
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ HEADER
794794
795795
import 'bar.dart';
796796
797+
// ignore_for_file: type=lint
798+
797799
/// The translations for English (`en`).
798800
class FooEn extends Foo {
799801
FooEn([String locale = 'en']) : super(locale);
@@ -894,6 +896,8 @@ flutter:\r
894896
expect(fs.file('/lib/l10n/app_localizations_en.dart').readAsStringSync(), '''
895897
import 'app_localizations.dart';
896898
899+
// ignore_for_file: type=lint
900+
897901
/// The translations for English (`en`).
898902
class AppLocalizationsEn extends AppLocalizations {
899903
AppLocalizationsEn([String locale = 'en']) : super(locale);
@@ -925,6 +929,8 @@ HEADER
925929
926930
import 'app_localizations.dart';
927931
932+
// ignore_for_file: type=lint
933+
928934
/// The translations for English (`en`).
929935
class AppLocalizationsEn extends AppLocalizations {
930936
AppLocalizationsEn([String locale = 'en']) : super(locale);

0 commit comments

Comments
 (0)