diff --git a/packages/flutter/lib/src/cupertino/localizations.dart b/packages/flutter/lib/src/cupertino/localizations.dart index 05e478331e..ce15d6662f 100644 --- a/packages/flutter/lib/src/cupertino/localizations.dart +++ b/packages/flutter/lib/src/cupertino/localizations.dart @@ -213,6 +213,9 @@ class _CupertinoLocalizationsDelegate extends LocalizationsDelegate false; + + @override + String toString() => 'DefaultCupertinoLocalizations.delegate(en_US)'; } /// US English strings for the cupertino widgets. diff --git a/packages/flutter/lib/src/material/material_localizations.dart b/packages/flutter/lib/src/material/material_localizations.dart index 5927243784..9fa3798397 100644 --- a/packages/flutter/lib/src/material/material_localizations.dart +++ b/packages/flutter/lib/src/material/material_localizations.dart @@ -338,6 +338,9 @@ class _MaterialLocalizationsDelegate extends LocalizationsDelegate false; + + @override + String toString() => 'DefaultMaterialLocalizations.delegate(en_US)'; } /// US English strings for the material widgets. diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart index 37274867b8..ed6d941688 100644 --- a/packages/flutter/lib/src/widgets/app.dart +++ b/packages/flutter/lib/src/widgets/app.dart @@ -5,6 +5,7 @@ import 'dart:async'; import 'dart:ui' as ui show window; +import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; import 'banner.dart'; @@ -769,6 +770,53 @@ class _WidgetsAppState extends State implements WidgetsBindingObserv // BUILDER + bool _debugCheckLocalizations(Locale appLocale) { + assert(() { + final Set unsupportedTypes = + _localizationsDelegates.map((LocalizationsDelegate delegate) => delegate.type).toSet(); + for (LocalizationsDelegate delegate in _localizationsDelegates) { + if (!unsupportedTypes.contains(delegate.type)) + continue; + if (delegate.isSupported(appLocale)) + unsupportedTypes.remove(delegate.type); + } + if (unsupportedTypes.isEmpty) + return true; + + // Currently the Cupertino library only provides english localizations. + // Remove this when https://github.com/flutter/flutter/issues/23847 + // is fixed. + if (listEquals(unsupportedTypes.map((Type type) => type.toString()).toList(), ['CupertinoLocalizations'])) + return true; + + final StringBuffer message = StringBuffer(); + message.writeln('\u2550' * 8); + message.writeln( + 'Warning: This application\'s locale, $appLocale, is not supported by all of its\n' + 'localization delegates.' + ); + for (Type unsupportedType in unsupportedTypes) { + // Currently the Cupertino library only provides english localizations. + // Remove this when https://github.com/flutter/flutter/issues/23847 + // is fixed. + if (unsupportedType.toString() == 'CupertinoLocalizations') + continue; + message.writeln( + '> A $unsupportedType delegate that supports the $appLocale locale was not found.' + ); + } + message.writeln( + 'See https://flutter.io/tutorials/internationalization/ for more\n' + 'information about configuring an app\'s locale, supportedLocales,\n' + 'and localizationsDelegates parameters.' + ); + message.writeln('\u2550' * 8); + debugPrint(message.toString()); + return true; + }()); + return true; + } + @override Widget build(BuildContext context) { Widget navigator; @@ -874,12 +922,16 @@ class _WidgetsAppState extends State implements WidgetsBindingObserv ); } + final Locale appLocale = widget.locale != null + ? _resolveLocale(widget.locale, widget.supportedLocales) + : _locale; + + assert(_debugCheckLocalizations(appLocale)); + return MediaQuery( data: MediaQueryData.fromWindow(ui.window), child: Localizations( - locale: widget.locale != null - ? _resolveLocale(widget.locale, widget.supportedLocales) - : _locale, + locale: appLocale, delegates: _localizationsDelegates.toList(), child: title, ), diff --git a/packages/flutter/lib/src/widgets/localizations.dart b/packages/flutter/lib/src/widgets/localizations.dart index d2c1f44e26..459a34c511 100644 --- a/packages/flutter/lib/src/widgets/localizations.dart +++ b/packages/flutter/lib/src/widgets/localizations.dart @@ -181,6 +181,9 @@ class _WidgetsLocalizationsDelegate extends LocalizationsDelegate false; + + @override + String toString() => 'DefaultWidgetsLocalizations.delegate(en_US)'; } /// US English localizations for the widgets library. diff --git a/packages/flutter_localizations/lib/src/material_localizations.dart b/packages/flutter_localizations/lib/src/material_localizations.dart index 95151ce12d..f56b84099d 100644 --- a/packages/flutter_localizations/lib/src/material_localizations.dart +++ b/packages/flutter_localizations/lib/src/material_localizations.dart @@ -641,4 +641,7 @@ class _MaterialLocalizationsDelegate extends LocalizationsDelegate false; + + @override + String toString() => 'GlobalMaterialLocalizations.delegate(${kSupportedLanguages.length} locales)'; } diff --git a/packages/flutter_localizations/lib/src/widgets_localizations.dart b/packages/flutter_localizations/lib/src/widgets_localizations.dart index 45d7522c07..4150e19791 100644 --- a/packages/flutter_localizations/lib/src/widgets_localizations.dart +++ b/packages/flutter_localizations/lib/src/widgets_localizations.dart @@ -74,4 +74,7 @@ class _WidgetsLocalizationsDelegate extends LocalizationsDelegate false; + + @override + String toString() => 'GlobalWidgetsLocalizations.delegate(all locales)'; }