Skip to content

Commit

Permalink
update generated localized message files in the stocks test app (#148…
Browse files Browse the repository at this point in the history
…741)

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)).
  • Loading branch information
andrewkolos authored Jun 3, 2024
1 parent 0e7295f commit be72479
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion dev/benchmarks/test_apps/stocks/lib/i18n/regenerate.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
30 changes: 16 additions & 14 deletions dev/benchmarks/test_apps/stocks/lib/i18n/stock_strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -97,7 +99,7 @@ abstract class StockStrings {
static const List<Locale> supportedLocales = <Locale>[
Locale('en'),
Locale('en', 'US'),
Locale('es'),
Locale('es')
];

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

@override
Future<StockStrings> load(Locale locale) {
return SynchronousFuture<StockStrings>(_lookupStockStrings(locale));
return SynchronousFuture<StockStrings>(lookupStockStrings(locale));
}

@override
Expand All @@ -134,16 +136,16 @@ class _StockStringsDelegate extends LocalizationsDelegate<StockStrings> {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.
///
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit be72479

Please sign in to comment.