Skip to content

Commit

Permalink
introduce localized text geometry in MaterialLocalizations (flutter#1…
Browse files Browse the repository at this point in the history
…1829)

* introduce localized text geometry in MaterialLocalizations

* remove geometry from color text themes

* fix merge conflict

* optional Localizations

* fix fallback; test; docs
  • Loading branch information
yjbanov committed Sep 22, 2017
1 parent f4f20c2 commit b9e1be9
Show file tree
Hide file tree
Showing 25 changed files with 645 additions and 117 deletions.
15 changes: 15 additions & 0 deletions packages/flutter/lib/src/material/i18n/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/// This variable is used by [MaterialLocalizations].
const Map<String, Map<String, String>> localizations = const <String, Map<String, String>> {
"ar": const <String, String>{
"scriptCategory": r"tall",
"timeOfDayFormat": r"h:mm a",
"openAppDrawerTooltip": r"افتح قائمة التنقل",
"backButtonTooltip": r"الى الخلف",
Expand Down Expand Up @@ -40,6 +41,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"postMeridiemAbbreviation": r"م",
},
"de": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"Navigationsmenü öffnen",
"backButtonTooltip": r"Zurück",
Expand Down Expand Up @@ -68,6 +70,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"LIZENZEN ANZEIGEN",
},
"en": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"h:mm a",
"openAppDrawerTooltip": r"Open navigation menu",
"backButtonTooltip": r"Back",
Expand Down Expand Up @@ -107,6 +110,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"timeOfDayFormat": r"HH:mm",
},
"es": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"H:mm",
"openAppDrawerTooltip": r"Abrir el menú de navegación",
"backButtonTooltip": r"Espalda",
Expand Down Expand Up @@ -140,6 +144,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"postMeridiemAbbreviation": r"PM",
},
"fa": const <String, String>{
"scriptCategory": r"tall",
"timeOfDayFormat": r"H:mm",
"openAppDrawerTooltip": r"منوی ناوبری را باز کنید",
"backButtonTooltip": r"بازگشت",
Expand All @@ -166,6 +171,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"مشاهده مجوز",
},
"fr": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"Ouvrir le menu de navigation",
"backButtonTooltip": r"Retour",
Expand Down Expand Up @@ -197,6 +203,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"timeOfDayFormat": r"HH 'h' mm",
},
"he": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"H:mm",
"openAppDrawerTooltip": r"פתח תפריט ניווט",
"backButtonTooltip": r"אחורה",
Expand All @@ -223,6 +230,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"ראה רישיונות",
},
"it": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"Apri il menu di navigazione",
"backButtonTooltip": r"Indietro",
Expand All @@ -249,6 +257,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"VEDI LE LICENZE",
},
"ja": const <String, String>{
"scriptCategory": r"dense",
"timeOfDayFormat": r"H:mm",
"openAppDrawerTooltip": r"ナビゲーションメニューを開く",
"backButtonTooltip": r"戻る",
Expand All @@ -275,6 +284,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"ライセンス表記",
},
"ps": const <String, String>{
"scriptCategory": r"tall",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"د پرانیستی نیینګ مینو",
"backButtonTooltip": r"شاته",
Expand All @@ -301,6 +311,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"لیدلس وګورئ",
},
"pt": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"Abrir menu de navegação",
"backButtonTooltip": r"Costas",
Expand All @@ -327,6 +338,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"VER LICENÇAS",
},
"ru": const <String, String>{
"scriptCategory": r"English-like",
"timeOfDayFormat": r"H:mm",
"openAppDrawerTooltip": r"Открыть меню навигации",
"backButtonTooltip": r"Назад",
Expand Down Expand Up @@ -355,6 +367,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"ПРОСМОТРЕТЬ ЛИЦЕНЗИИ",
},
"sd": const <String, String>{
"scriptCategory": r"tall",
"timeOfDayFormat": r"HH:mm",
"openAppDrawerTooltip": r"اوپن جي مينڊيٽ مينيو",
"backButtonTooltip": r"پوئتي",
Expand All @@ -381,6 +394,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"viewLicensesButtonLabel": r"لائسنس ڏسو",
},
"ur": const <String, String>{
"scriptCategory": r"tall",
"timeOfDayFormat": r"h:mm a",
"openAppDrawerTooltip": r"کھولیں نیویگیشن مینو",
"backButtonTooltip": r"واپس",
Expand Down Expand Up @@ -409,6 +423,7 @@ const Map<String, Map<String, String>> localizations = const <String, Map<String
"postMeridiemAbbreviation": r"PM",
},
"zh": const <String, String>{
"scriptCategory": r"dense",
"timeOfDayFormat": r"ah:mm",
"openAppDrawerTooltip": r"打开导航菜单",
"backButtonTooltip": r"返回",
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_ar.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "tall",
"timeOfDayFormat": "h:mm a",
"openAppDrawerTooltip": "افتح قائمة التنقل",
"backButtonTooltip": "الى الخلف",
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_de.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "German time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "German time format does not use p.m. indicator" },
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/material/i18n/material_en.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"scriptCategory": "English-like",
"@scriptCategory": {
"description": "The name of the language's script category (see https://material.io/guidelines/style/typography.html#typography-language-categories-reference)",
"type": "text"
},

"timeOfDayFormat": "h:mm a",
"@timeOfDayFormat": {
"description": "The ICU 'Short Time' pattern, such as 'HH:mm', 'h:mm a', 'H:mm'. See: http://demo.icu-project.org/icu-bin/locexp?d_=en&_=en_US",
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_es.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "H:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Standard Spanish time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Standard Spanish time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_fa.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "tall",
"timeOfDayFormat": "H:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Farsi time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Farsi time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_fr.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "French time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "French time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_he.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "H:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Hebrew time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Hebrew time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_it.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Italian time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Italian time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_ja.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "dense",
"timeOfDayFormat": "H:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Japanese time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Japanese time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_ps.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "tall",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Pashto time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Pashto time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_pt.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Portuguese time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Portuguese time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_ru.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "English-like",
"timeOfDayFormat": "H:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Russian time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Russian time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_sd.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "tall",
"timeOfDayFormat": "HH:mm",
"@anteMeridiemAbbreviation": { "notUsed": "Sindhi time format does not use a.m. indicator" },
"@postMeridiemAbbreviation": { "notUsed": "Sindhi time format does not use p.m. indicator" },
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_ur.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "tall",
"timeOfDayFormat": "h:mm a",
"openAppDrawerTooltip": "کھولیں نیویگیشن مینو",
"backButtonTooltip": "واپس",
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/i18n/material_zh.arb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"scriptCategory": "dense",
"timeOfDayFormat": "ah:mm",
"openAppDrawerTooltip": "打开导航菜单",
"backButtonTooltip": "返回",
Expand Down
18 changes: 18 additions & 0 deletions packages/flutter/lib/src/material/material_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart' as intl;

import 'i18n/localizations.dart';
import 'typography.dart';

/// Defines the localized resource values used by the Material widgets.
///
Expand Down Expand Up @@ -95,6 +96,19 @@ abstract class MaterialLocalizations {
/// each supported layout.
TimeOfDayFormat get timeOfDayFormat;

/// Provides geometric text preferences for the current locale.
///
/// This text theme is incomplete. For example, it lacks text color
/// information. This theme must be merged with another text theme that
/// provides the missing values. The text styles provided by this theme have
/// their [TextStyle.inherit] property set to `true`.
///
/// Typically a complete theme is obtained via [Theme.of], which can be
/// localized using the [Localizations] widget.
///
/// See also: https://material.io/guidelines/style/typography.html
TextTheme get localTextGeometry;

/// The `MaterialLocalizations` from the closest [Localizations] instance
/// that encloses the given context.
///
Expand Down Expand Up @@ -287,6 +301,10 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
return _icuTimeOfDayToEnum[icuShortTimePattern];
}

/// Looks up text geometry defined in [MaterialTextGeometry].
@override
TextTheme get localTextGeometry => MaterialTextGeometry.forScriptCategory(_nameToValue["scriptCategory"]);

/// Creates an object that provides localized resource values for the
/// for the widgets of the material library.
///
Expand Down
12 changes: 11 additions & 1 deletion packages/flutter/lib/src/material/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';

import 'material_localizations.dart';
import 'theme_data.dart';
import 'typography.dart';

export 'theme_data.dart' show Brightness, ThemeData;

Expand Down Expand Up @@ -65,6 +67,10 @@ class Theme extends StatelessWidget {
/// The data from the closest [Theme] instance that encloses the given
/// context.
///
/// If the given context is enclosed in a [Localizations] widget providing
/// [MaterialLocalizations], the returned data is localized according to the
/// nearest available [MaterialLocalizations].
///
/// Defaults to [new ThemeData.fallback] if there is no [Theme] in the given
/// build context.
///
Expand Down Expand Up @@ -123,7 +129,11 @@ class Theme extends StatelessWidget {
return null;
return inheritedTheme.theme.data;
}
return (inheritedTheme != null) ? inheritedTheme.theme.data : _kFallbackTheme;

final ThemeData colorTheme = (inheritedTheme != null) ? inheritedTheme.theme.data : _kFallbackTheme;
final MaterialLocalizations localizations = MaterialLocalizations.of(context);
final TextTheme geometryTheme = localizations?.localTextGeometry ?? MaterialTextGeometry.englishLike;
return ThemeData.localize(colorTheme, geometryTheme);
}

@override
Expand Down

0 comments on commit b9e1be9

Please sign in to comment.