-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language-specific LocalizationDelegates #12645
Language-specific LocalizationDelegates #12645
Conversation
@@ -188,6 +188,9 @@ class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocal | |||
const _MaterialLocalizationsDelegate(); | |||
|
|||
@override | |||
bool isSupported(Locale locale) => locale.languageCode == 'en'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only en-US, right?
final Set<Type> types = new Set<Type>(); | ||
final List<LocalizationsDelegate<dynamic>> delegates = <LocalizationsDelegate<dynamic>>[]; | ||
for (LocalizationsDelegate<dynamic> delegate in allDelegates) { | ||
if (!types.contains(delegate.type)) { | ||
if (delegate.isSupported(locale) && !types.contains(delegate.type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would flip the order in which you make these calls, so that we don't contact the delegate if we don't need to.
@@ -97,6 +99,12 @@ abstract class LocalizationsDelegate<T> { | |||
/// const constructors so that they can be used in const expressions. | |||
const LocalizationsDelegate(); | |||
|
|||
/// Return true if the instance of 'T' loaded by this delegate's [load] | |||
/// method supports the given `locale`'s language. | |||
bool isSupported(Locale locale) => true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe prefix with something like:
/// Whether resources for the given locale can be loaded by this delegate.
///
Also either use backticks or no quotes at all around T. Single quotes makes it look like a string.
/// method supports the given `locale`'s language. | ||
bool isSupported(Locale locale) => true; | ||
// TODO(hansmuller): remove the default implementation after existing | ||
// apps have had a chance to update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless you mean that you plan to remove it in a couple of days, i would remove it now. the longer we leave this the more likely it is we'll have people depending on it.
// This is convenient simplification. It would be more correct test if locale's | ||
// text-direction is LTR. | ||
@override | ||
bool isSupported(Locale locale) => true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this'll get resolved once we have the concrete classes, right?
@@ -68,6 +68,9 @@ class _WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocaliz | |||
const _WidgetsLocalizationsDelegate(); | |||
|
|||
@override | |||
bool isSupported(Locale locale) => true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only en-US, right?
718cc44
to
0bc7771
Compare
0bc7771
to
72151fb
Compare
Make it easier to add language-specific versions of MaterialLocalizations.
Apps can define their own implementations of MaterialLocalizations that support languages which are not supported by the flutter_localizations package.
When a Flutter app starts or switches locales it will now select the first LocalizationDelegate for each LocalizationDelegate.type that supports the new locale. LocalizationDelegates must override their isSupported(Locale) method.
So to add material library support for a new language an app would define a subclass of MaterialLocalizations, say MyPolishMaterialLocalizations. The new Polish localizations would be loaded by a LocalizationsDelegate defined like this:
A Material app that included the new Polish localizations would be created like this: