diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 693455b17c..cfdc23053c 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -10,6 +10,7 @@ import 'colors.dart'; import 'debug.dart'; import 'feedback.dart'; import 'icons.dart'; +import 'material_localizations.dart'; import 'tooltip.dart'; /// A material design chip. @@ -146,9 +147,7 @@ class Chip extends StatelessWidget { children.add(new GestureDetector( onTap: Feedback.wrapForTap(onDeleted, context), child: new Tooltip( - // TODO(gspencer): Internationalize this text. - // https://github.com/flutter/flutter/issues/12378 - message: deleteButtonTooltipMessage ?? 'Delete "$label"', + message: deleteButtonTooltipMessage ?? MaterialLocalizations.of(context).deleteButtonTooltip, child: new Container( padding: const EdgeInsets.symmetric(horizontal: 4.0), child: new Icon( diff --git a/packages/flutter/lib/src/material/material_localizations.dart b/packages/flutter/lib/src/material/material_localizations.dart index 2887240ef0..cc48fde5d7 100644 --- a/packages/flutter/lib/src/material/material_localizations.dart +++ b/packages/flutter/lib/src/material/material_localizations.dart @@ -10,6 +10,31 @@ import 'package:flutter/widgets.dart'; import 'time.dart'; import 'typography.dart'; +// ADDING A NEW STRING +// +// If you (someone contributing to the Flutter framework) want to add a new +// string to the MaterialLocalizations object (e.g. because you've added a new +// widget and it has a tooltip), follow these steps: +// +// 1. Add the new getter to MaterialLocalizations below. +// +// 2. Implement a default value in DefaultMaterialLocalizations below. +// +// 3. Add a test to test/material/localizations_test.dart that verifies that +// this new value is implemented. +// +// 4. Update the flutter_localizations package. To add a new string to the +// flutter_localizations package, you must first add it to the English +// translations (lib/src/l10n/material_en.arb), including a description, then +// you must add it to every other language (all the other *.arb files in that +// same directory), including a best guess as to the translation, e.g. +// obtained by optimistic use of Google Translate +// (https://translate.google.com/). There is a README file with further +// information in the lib/src/l10n/ directory. +// +// 5. If you are a Google employee, you should then also follow the instructions +// at go/flutter-l10n. If you're not, don't worry about it. + /// Defines the localized resource values used by the Material widgets. /// /// See also: @@ -28,6 +53,9 @@ abstract class MaterialLocalizations { /// The [CloseButton]'s tooltip. String get closeButtonTooltip; + /// The tooltip for the delete button on a [Chip]. + String get deleteButtonTooltip; + /// The tooltip for the [MonthPicker]'s "next month" button. String get nextMonthTooltip; @@ -229,7 +257,6 @@ class DefaultMaterialLocalizations implements MaterialLocalizations { /// function, rather than constructing this class directly. const DefaultMaterialLocalizations(); - // Ordered to match DateTime.MONDAY=1, DateTime.SUNDAY=6 static const List_shortWeekdays = const [ 'Mon', @@ -399,6 +426,9 @@ class DefaultMaterialLocalizations implements MaterialLocalizations { @override String get closeButtonTooltip => 'Close'; + @override + String get deleteButtonTooltip => 'Delete'; + @override String get nextMonthTooltip => 'Next month'; diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index 5d146729ec..31e80f0c16 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -219,6 +219,7 @@ void main() { expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0)); expect(tester.getSize(find.byType(Chip)), const Size(800.0, 32.0)); }); + testWidgets('Chip supports RTL', (WidgetTester tester) async { final Widget test = new Overlay( initialEntries: [ @@ -238,17 +239,31 @@ void main() { ); await tester.pumpWidget( - new Directionality( - textDirection: TextDirection.rtl, - child: test, + new Localizations( + locale: const Locale('en', 'US'), + delegates: >[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: new Directionality( + textDirection: TextDirection.rtl, + child: test, + ), ), ); expect(tester.getCenter(find.text('ABC')).dx, greaterThan(tester.getCenter(find.byType(Icon)).dx)); await tester.pumpWidget( - new Directionality( - textDirection: TextDirection.ltr, - child: test, + new Localizations( + locale: const Locale('en', 'US'), + delegates: >[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: new Directionality( + textDirection: TextDirection.ltr, + child: test, + ), ), ); expect(tester.getCenter(find.text('ABC')).dx, lessThan(tester.getCenter(find.byType(Icon)).dx)); @@ -411,24 +426,31 @@ void main() { final GlobalKey keyA = new GlobalKey(); final GlobalKey keyB = new GlobalKey(); await tester.pumpWidget( - new Directionality( - textDirection: TextDirection.ltr, - child: new Overlay( - initialEntries: [ - new OverlayEntry( - builder: (BuildContext context) { - return new Material( - child: new Center( - child: new Chip( - avatar: new Placeholder(key: keyA), - label: new Placeholder(key: keyB), - onDeleted: () { }, + new Localizations( + locale: const Locale('en', 'US'), + delegates: >[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: new Directionality( + textDirection: TextDirection.ltr, + child: new Overlay( + initialEntries: [ + new OverlayEntry( + builder: (BuildContext context) { + return new Material( + child: new Center( + child: new Chip( + avatar: new Placeholder(key: keyA), + label: new Placeholder(key: keyB), + onDeleted: () { }, + ), ), - ), - ); - }, - ), - ], + ); + }, + ), + ], + ), ), ), ); @@ -444,24 +466,31 @@ void main() { final GlobalKey keyA = new GlobalKey(); final GlobalKey keyB = new GlobalKey(); await tester.pumpWidget( - new Directionality( - textDirection: TextDirection.rtl, - child: new Overlay( - initialEntries: [ - new OverlayEntry( - builder: (BuildContext context) { - return new Material( - child: new Center( - child: new Chip( - avatar: new Placeholder(key: keyA), - label: new Placeholder(key: keyB), - onDeleted: () { }, + new Localizations( + locale: const Locale('en', 'US'), + delegates: >[ + DefaultWidgetsLocalizations.delegate, + DefaultMaterialLocalizations.delegate, + ], + child: new Directionality( + textDirection: TextDirection.rtl, + child: new Overlay( + initialEntries: [ + new OverlayEntry( + builder: (BuildContext context) { + return new Material( + child: new Center( + child: new Chip( + avatar: new Placeholder(key: keyA), + label: new Placeholder(key: keyB), + onDeleted: () { }, + ), ), - ), - ); - }, - ), - ], + ); + }, + ), + ], + ), ), ), ); diff --git a/packages/flutter/test/material/localizations_test.dart b/packages/flutter/test/material/localizations_test.dart index a9c7f33452..79973a8552 100644 --- a/packages/flutter/test/material/localizations_test.dart +++ b/packages/flutter/test/material/localizations_test.dart @@ -12,6 +12,7 @@ void main() { expect(localizations.openAppDrawerTooltip, isNotNull); expect(localizations.backButtonTooltip, isNotNull); expect(localizations.closeButtonTooltip, isNotNull); + expect(localizations.deleteButtonTooltip, isNotNull); expect(localizations.nextMonthTooltip, isNotNull); expect(localizations.previousMonthTooltip, isNotNull); expect(localizations.nextPageTooltip, isNotNull); diff --git a/packages/flutter_localizations/lib/src/l10n/README.md b/packages/flutter_localizations/lib/src/l10n/README.md index ff2ef14a8e..def1c6389c 100644 --- a/packages/flutter_localizations/lib/src/l10n/README.md +++ b/packages/flutter_localizations/lib/src/l10n/README.md @@ -127,7 +127,9 @@ the "Other" suffix. For example the English translations If you look at the comment at the top of `localizations.dart` you'll see that it was manually generated using a `dev/tools` app called -`gen_localizations` roughly like this: +`gen_localizations`. + +You can see what that script would generate by running this command: ```dart dart dev/tools/gen_localizations.dart packages/flutter_localizations/lib/src/l10n material @@ -144,14 +146,20 @@ been updated. The app's first parameter is the path to this directory, the second is the file name prefix (the file name less the locale suffix) for the .arb files in this directory. +To in-place update the `localizations.dart` file using the default +values, you can just run: + +```dart +dart dev/tools/gen_localizations.dart --overwrite +``` + ### Translations Status, Reporting Errors -The transltations (the `.arb` files) in this directory are based on -the english translations in `material_en.arb`. As noted earlier, -material_en.arb, contains a small amount of descriptive information -for each resource ID, under the companion resources whose IDs begin -with '@'. +The translations (the `.arb` files) in this directory are based on the +English translations in `material_en.arb`. Google contributes +translations for all the languages supported by this package. +(Googlers, for more details see .) Not all of the translations represented here have been vetted by native speakers. The following translations have been reviewed by diff --git a/packages/flutter_localizations/lib/src/l10n/localizations.dart b/packages/flutter_localizations/lib/src/l10n/localizations.dart index 150afd5e29..9e304174d9 100644 --- a/packages/flutter_localizations/lib/src/l10n/localizations.dart +++ b/packages/flutter_localizations/lib/src/l10n/localizations.dart @@ -22,6 +22,7 @@ const Map> localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const > localizations = const _nameToValue['closeButtonTooltip']; + @override + String get deleteButtonTooltip => _nameToValue['deleteButtonTooltip']; + @override String get nextMonthTooltip => _nameToValue['nextMonthTooltip'];