Update gen_l10n tool to require base locale; Stocks app refresh (#51602)

This commit is contained in:
Shi-Hao Hong
2020-02-28 22:21:01 -08:00
committed by GitHub
parent 6a337a76dd
commit c98500dea3
13 changed files with 158 additions and 196 deletions

View File

@@ -8,6 +8,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
// ignore: unused_import
import 'package:intl/intl.dart' as intl;
// ignore_for_file: unnecessary_brace_in_string_interps
@@ -67,6 +68,7 @@ import 'package:intl/intl.dart' as intl;
abstract class @(class) {
@(class)(String locale) : assert(locale != null), _localeName = intl.Intl.canonicalizedLocale(locale.toString());
// ignore: unused_field
final String _localeName;
static @(class) of(BuildContext context) {

View File

@@ -423,6 +423,23 @@ class AppResourceBundleCollection {
languageToLocales[bundle.locale.languageCode].add(bundle.locale);
}
}
languageToLocales.forEach((String language, List<LocaleInfo> listOfCorrespondingLocales) {
final List<String> localeStrings = listOfCorrespondingLocales.map((LocaleInfo locale) {
return locale.toString();
}).toList();
if (!localeStrings.contains(language)) {
throw L10nException(
'Arb file for a fallback, $language, does not exist, even though \n'
'the following locale(s) exist: $listOfCorrespondingLocales. \n'
'When locales specify a script code or country code, a \n'
'base locale (without the script code or country code) should \n'
'exist as the fallback. Please create a {fileName}_$language.arb \n'
'file.'
);
}
});
return AppResourceBundleCollection._(directory, localeToBundle, languageToLocales);
}