Unverified Commit 291602db authored by Yegor's avatar Yegor Committed by GitHub

localize a11y tab labels in the TabBar (#13714)

* localize a11y tab labels in the TabBar

* break import cycle

* test boilerplate

* fix German translation

* more test boilerplate fixes
parent 68736081
......@@ -85,6 +85,14 @@ abstract class MaterialLocalizations {
/// Title for the [PaginatedDataTable]'s "rows per page" footer.
String get rowsPerPageTitle;
/// The accessibility label used on a tab in a [TabBar].
///
/// This message describes the index of the selected tab and how many tabs
/// there are, e.g. 'Tab 1 of 2' in United States English.
///
/// `tabIndex` and `tabCount` must be greater than or equal to one.
String tabLabel({int tabIndex, int tabCount});
/// Title for the [PaginatedDataTable]'s selected row count header.
String selectedRowCountTitle(int selectedRowCount);
......@@ -517,6 +525,13 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
@override
String get rowsPerPageTitle => 'Rows per page:';
@override
String tabLabel({int tabIndex, int tabCount}) {
assert(tabIndex >= 1);
assert(tabCount >= 1);
return 'Tab $tabIndex of $tabCount';
}
@override
String selectedRowCountTitle(int selectedRowCount) {
switch (selectedRowCount) {
......
......@@ -16,6 +16,7 @@ import 'constants.dart';
import 'debug.dart';
import 'ink_well.dart';
import 'material.dart';
import 'material_localizations.dart';
import 'tab_controller.dart';
import 'theme.dart';
......@@ -747,6 +748,7 @@ class _TabBarState extends State<TabBar> {
@override
Widget build(BuildContext context) {
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
if (_controller.length == 0) {
return new Container(
height: _kTabHeight + widget.indicatorWeight,
......@@ -811,8 +813,7 @@ class _TabBarState extends State<TabBar> {
wrappedTabs[index],
new Semantics(
selected: index == _currentIndex,
// TODO(goderbauer): I10N-ify
label: 'Tab ${index + 1} of $tabCount',
label: localizations.tabLabel(tabIndex: index + 1, tabCount: tabCount),
),
]
),
......
......@@ -8,33 +8,40 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
Widget buildSliverAppBarApp({ bool floating, bool pinned, double expandedHeight, bool snap: false }) {
return new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(),
child: new Scaffold(
body: new DefaultTabController(
length: 3,
child: new CustomScrollView(
primary: true,
slivers: <Widget>[
new SliverAppBar(
title: const Text('AppBar Title'),
floating: floating,
pinned: pinned,
expandedHeight: expandedHeight,
snap: snap,
bottom: new TabBar(
tabs: <String>['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(),
return new Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(),
child: new Scaffold(
body: new DefaultTabController(
length: 3,
child: new CustomScrollView(
primary: true,
slivers: <Widget>[
new SliverAppBar(
title: const Text('AppBar Title'),
floating: floating,
pinned: pinned,
expandedHeight: expandedHeight,
snap: snap,
bottom: new TabBar(
tabs: <String>['A','B','C'].map((String t) => new Tab(text: 'TAB $t')).toList(),
),
),
),
new SliverToBoxAdapter(
child: new Container(
height: 1200.0,
color: Colors.orange[400],
new SliverToBoxAdapter(
child: new Container(
height: 1200.0,
color: Colors.orange[400],
),
),
),
],
],
),
),
),
),
......
......@@ -15,10 +15,17 @@ import '../rendering/recording_canvas.dart';
import '../widgets/semantics_tester.dart';
Widget boilerplate({ Widget child, TextDirection textDirection: TextDirection.ltr }) {
return new Directionality(
textDirection: textDirection,
child: new Material(
child: child,
return new Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: new Directionality(
textDirection: textDirection,
child: new Material(
child: child,
),
),
);
}
......
......@@ -21,75 +21,82 @@ class _CustomPhysics extends ClampingScrollPhysics {
}
Widget buildTest({ ScrollController controller, String title:'TTTTTTTT' }) {
return new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(),
child: new Scaffold(
body: new DefaultTabController(
length: 4,
child: new NestedScrollView(
controller: controller,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
title: new Text(title),
pinned: true,
expandedHeight: 200.0,
forceElevated: innerBoxIsScrolled,
bottom: const TabBar(
tabs: const <Tab>[
const Tab(text: 'AA'),
const Tab(text: 'BB'),
const Tab(text: 'CC'),
const Tab(text: 'DD'),
return new Localizations(
locale: const Locale('en', 'US'),
delegates: <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
child: new Directionality(
textDirection: TextDirection.ltr,
child: new MediaQuery(
data: const MediaQueryData(),
child: new Scaffold(
body: new DefaultTabController(
length: 4,
child: new NestedScrollView(
controller: controller,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
title: new Text(title),
pinned: true,
expandedHeight: 200.0,
forceElevated: innerBoxIsScrolled,
bottom: const TabBar(
tabs: const <Tab>[
const Tab(text: 'AA'),
const Tab(text: 'BB'),
const Tab(text: 'CC'),
const Tab(text: 'DD'),
],
),
),
];
},
body: new TabBarView(
children: <Widget>[
new ListView(
children: <Widget>[
new Container(
height: 300.0,
child: const Text('aaa1'),
),
new Container(
height: 200.0,
child: const Text('aaa2'),
),
new Container(
height: 100.0,
child: const Text('aaa3'),
),
new Container(
height: 50.0,
child: const Text('aaa4'),
),
],
),
),
];
},
body: new TabBarView(
children: <Widget>[
new ListView(
children: <Widget>[
new Container(
height: 300.0,
child: const Text('aaa1'),
),
new Container(
height: 200.0,
child: const Text('aaa2'),
),
new Container(
height: 100.0,
child: const Text('aaa3'),
),
new Container(
height: 50.0,
child: const Text('aaa4'),
),
],
),
new ListView(
children: <Widget>[
new Container(
height: 100.0,
child: const Text('bbb1'),
),
],
),
new Container(
child: const Center(child: const Text('ccc1')),
),
new ListView(
children: <Widget>[
new Container(
height: 10000.0,
child: const Text('ddd1'),
),
],
),
],
new ListView(
children: <Widget>[
new Container(
height: 100.0,
child: const Text('bbb1'),
),
],
),
new Container(
child: const Center(child: const Text('ccc1')),
),
new ListView(
children: <Widget>[
new Container(
height: 10000.0,
child: const Text('ddd1'),
),
],
),
],
),
),
),
),
......
......@@ -20,6 +20,7 @@
"pageRowsInfoTitle": "من $firstRow إلى $lastRow من إجمالي $rowCount",
"pageRowsInfoTitleApproximate": "من $firstRow إلى $lastRow من إجمالي $rowCount تقريبًا",
"rowsPerPageTitle": "عدد الصفوف في الصفحة:",
"tabLabel": "من $tabIndex من إجمالي $tabCount",
"selectedRowCountTitleOther": "تم اختيار $selectedRowCount عنصر",
"cancelButtonLabel": "إلغاء",
"closeButtonLabel": "إغلاق",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow von $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow von etwa $rowCount",
"rowsPerPageTitle": "Zeilen pro Seite:",
"tabLabel": "Tabulator $tabIndex von $tabCount",
"selectedRowCountTitleZero": "Keine Objekte ausgewählt",
"selectedRowCountTitleOne": "1 Element ausgewählt",
"selectedRowCountTitleOther": "$selectedRowCount Elemente ausgewählt",
......
......@@ -82,6 +82,12 @@
"description": "The caption for the drop-down button on a paginated data table's footer that allows the user to control the number of rows of data per page of the table."
},
"tabLabel": "Tab $tabIndex of $tabCount",
"@tabLabel": {
"description": "The accessibility label used on a tab. This message describes the index of the selected tab and how many tabs there are, e.g. 'Tab 1 of 2'. All values are greater than or equal to one.",
"parameters": "tabIndex, tabCount"
},
"selectedRowCountTitleZero": "No items selected",
"selectedRowCountTitleOne": "1 item selected",
"selectedRowCountTitleOther": "$selectedRowCount items selected",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow‑$lastRow de $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow‑$lastRow de aproximadamente $rowCount",
"rowsPerPageTitle": "Filas por página:",
"tabLabel": "$tabIndex de $tabCount",
"selectedRowCountTitleZero": "No se han seleccionado elementos",
"selectedRowCountTitleOne": "1 elemento seleccionado",
"selectedRowCountTitleOther": "$selectedRowCount elementos seleccionados",
......
......@@ -16,6 +16,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow از $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow از حدود $rowCount",
"rowsPerPageTitle": "ردیف در هر صفحه:",
"tabLabel": "$tabIndex از $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount مورد انتخاب شدند",
"cancelButtonLabel": "لغو",
"closeButtonLabel": "بستن",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow – $lastRow sur $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow – $lastRow sur environ $rowCount",
"rowsPerPageTitle": "Lignes par page :",
"tabLabel": "$tabIndex sur $tabCount",
"selectedRowCountTitleZero": "Aucun élément sélectionné",
"selectedRowCountTitleOne": "1 élément sélectionné",
"selectedRowCountTitleOther": "$selectedRowCount éléments sélectionnés",
......
......@@ -18,6 +18,7 @@
"pageRowsInfoTitle": "$lastRow–$firstRow מתוך $rowCount",
"pageRowsInfoTitleApproximate": "$lastRow–$firstRow מתוך כ-$rowCount",
"rowsPerPageTitle": "שורות בכל דף:",
"tabLabel": "$tabIndex מתוך $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount פריטים נבחרו",
"cancelButtonLabel": "ביטול",
"closeButtonLabel": "סגירה",
......
......@@ -16,6 +16,7 @@
"pageRowsInfoTitle": "$firstRow-$lastRow di $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow-$lastRow di circa $rowCount",
"rowsPerPageTitle": "Righe per pagina:",
"tabLabel": "$tabIndex di $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount elementi selezionati",
"cancelButtonLabel": "ANNULLA",
"closeButtonLabel": "CHIUDI",
......
......@@ -16,6 +16,7 @@
"pageRowsInfoTitle": "$firstRow - $lastRow 行(合計 $rowCount 行)",
"pageRowsInfoTitleApproximate": "$firstRow – $lastRow 行(合計約 $rowCount 行)",
"rowsPerPageTitle": "ページあたりの行数:",
"tabLabel": "$tabIndex 行(合計 $tabCount 行)",
"selectedRowCountTitleOther": "$selectedRowCount 件のアイテムを選択中",
"cancelButtonLabel": "キャンセル",
"closeButtonLabel": "閉じる",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$rowCount행 중 $firstRow~$lastRow행",
"pageRowsInfoTitleApproximate": "약 $rowCount행 중 $firstRow~$lastRow행",
"rowsPerPageTitle": "페이지당 행 수:",
"tabLabel": "$tabCount행 중 $tabIndex행",
"selectedRowCountTitleOne": "항목 1개 선택됨",
"selectedRowCountTitleOther": "항목 $selectedRowCount개 선택됨",
"cancelButtonLabel": "취소",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow-$lastRow van $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow-$lastRow van ongeveer $rowCount",
"rowsPerPageTitle": "Rijen per pagina:",
"tabLabel": "$tabIndex van $tabCount",
"selectedRowCountTitleOne": "1 item geselecteerd",
"selectedRowCountTitleOther": "$selectedRowCount items geselecteerd",
"cancelButtonLabel": "ANNULEREN",
......
......@@ -17,6 +17,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow z $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow z około $rowCount",
"rowsPerPageTitle": "Wiersze na stronie:",
"tabLabel": "$tabIndex z $tabCount",
"selectedRowCountTitleOne": "1 wybrany element",
"selectedRowCountTitleOther": "$selectedRowCount wybranego elementu",
"cancelButtonLabel": "ANULUJ",
......
......@@ -17,6 +17,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow د $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow څخه $rowCount د",
"rowsPerPageTitle": "د هرې پاڼې پاڼې:",
"tabLabel": "$tabIndex د $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount توکي غوره شوي",
"cancelButtonLabel": "لغوه کول",
"closeButtonLabel": "تړل",
......
......@@ -20,6 +20,7 @@
"pageRowsInfoTitle": "$firstRow – $lastRow de $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow – $lastRow de aproximadamente $rowCount",
"rowsPerPageTitle": "Linhas por página:",
"tabLabel": "$tabIndex de $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount itens selecionados",
"cancelButtonLabel": "CANCELAR",
"closeButtonLabel": "FECHAR",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow из $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow из примерно $rowCount",
"rowsPerPageTitle": "Строк на странице:",
"tabLabel": "Закладка $tabIndex из $tabCount",
"aboutListTileTitle": "$applicationName: сведения",
"licensesPageTitle": "Лицензии",
"selectedRowCountTitleZero": "Строки не выбраны",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow-$lastRow จาก $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow จากประมาณ $rowCount",
"rowsPerPageTitle": "แถวต่อหน้า:",
"tabLabel": "$tabIndex จาก $tabCount",
"selectedRowCountTitleOne": "เลือกแล้ว 1 รายการ",
"selectedRowCountTitleOther": "เลือกแล้ว $selectedRowCount รายการ",
"cancelButtonLabel": "ยกเลิก",
......
......@@ -15,6 +15,7 @@
"pageRowsInfoTitle": "$firstRow-$lastRow / $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow-$lastRow / $rowCount",
"rowsPerPageTitle": "Sayfa başına satır sayısı:",
"tabLabel": "$tabIndex, $tabCount içinde",
"selectedRowCountTitleOne": "1 öğe seçildi",
"selectedRowCountTitleOther": "$selectedRowCount öğe seçildi",
"cancelButtonLabel": "İPTAL",
......
......@@ -16,6 +16,7 @@
"pageRowsInfoTitle": "$firstRow–$lastRow از $rowCount",
"pageRowsInfoTitleApproximate": "$firstRow–$lastRow $rowCount میں سے تقریباً",
"rowsPerPageTitle": "قطاریں فی صفحہ:",
"tabLabel": "$tabIndex از $tabCount",
"selectedRowCountTitleOther": "$selectedRowCount آئٹمز منتخب کیے گئے",
"cancelButtonLabel": "منسوخ کریں",
"closeButtonLabel": "بند کریں",
......
......@@ -12,6 +12,7 @@
"pageRowsInfoTitle": "第 $firstRow-$lastRow 行(共 $rowCount 行)",
"pageRowsInfoTitleApproximate": "第 $firstRow-$lastRow 行(共约 $rowCount 行)",
"rowsPerPageTitle": "每页行数:",
"tabLabel": "第 $tabIndex 行(共 $tabCount 行)",
"selectedRowCountTitleOther": "已选择 $selectedRowCount 项内容",
"cancelButtonLabel": "取消",
"continueButtonLabel": "继续",
......
......@@ -272,6 +272,16 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
@override
String get rowsPerPageTitle => _translationBundle.rowsPerPageTitle;
@override
String tabLabel({int tabIndex, int tabCount}) {
assert(tabIndex >= 1);
assert(tabCount >= 1);
final String template = _translationBundle.tabLabel;
return template
.replaceFirst(r'$tabIndex', formatDecimal(tabIndex))
.replaceFirst(r'tabCount', formatDecimal(tabCount));
}
@override
String selectedRowCountTitle(int selectedRowCount) {
// TODO(hmuller): the rules for mapping from an integer value to
......
......@@ -61,19 +61,25 @@ void main() {
expect(localizations.selectedRowCountTitle(1), isNotNull);
expect(localizations.selectedRowCountTitle(2), isNotNull);
expect(localizations.selectedRowCountTitle(100), isNotNull);
expect(localizations.selectedRowCountTitle(0).contains(r'$selectedRowCount'), isFalse);
expect(localizations.selectedRowCountTitle(1).contains(r'$selectedRowCount'), isFalse);
expect(localizations.selectedRowCountTitle(2).contains(r'$selectedRowCount'), isFalse);
expect(localizations.selectedRowCountTitle(100).contains(r'$selectedRowCount'), isFalse);
expect(localizations.selectedRowCountTitle(0), isNot(contains(r'$selectedRowCount')));
expect(localizations.selectedRowCountTitle(1), isNot(contains(r'$selectedRowCount')));
expect(localizations.selectedRowCountTitle(2), isNot(contains(r'$selectedRowCount')));
expect(localizations.selectedRowCountTitle(100), isNot(contains(r'$selectedRowCount')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, true), isNotNull);
expect(localizations.pageRowsInfoTitle(1, 10, 100, false), isNotNull);
expect(localizations.pageRowsInfoTitle(1, 10, 100, true).contains(r'$firstRow'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, true).contains(r'$lastRow'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, true).contains(r'$rowCount'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, false).contains(r'$firstRow'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, false).contains(r'$lastRow'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, false).contains(r'$rowCount'), isFalse);
expect(localizations.pageRowsInfoTitle(1, 10, 100, true), isNot(contains(r'$firstRow')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, true), isNot(contains(r'$lastRow')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, true), isNot(contains(r'$rowCount')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, false), isNot(contains(r'$firstRow')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, false), isNot(contains(r'$lastRow')));
expect(localizations.pageRowsInfoTitle(1, 10, 100, false), isNot(contains(r'$rowCount')));
expect(localizations.tabLabel(tabIndex: 2, tabCount: 5), isNotNull);
expect(localizations.tabLabel(tabIndex: 2, tabCount: 5), isNot(contains('tabIndex')));
expect(localizations.tabLabel(tabIndex: 2, tabCount: 5), isNot(contains('tabCount')));
expect(() => localizations.tabLabel(tabIndex: 0, tabCount: 5), throwsAssertionError);
expect(() => localizations.tabLabel(tabIndex: 2, tabCount: 0), throwsAssertionError);
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment