Commit 9b5d663e authored by Yegor's avatar Yegor Committed by GitHub

Upgrade intl: use the new API for locale data and localized numerals (#12736)

* upgrade intl data; use local numerals in date picker

* use the shiny new public intl API

* address comments
parent 89a4a138
......@@ -43,7 +43,7 @@ Future<Null> main(List<String> rawArgs) async {
);
}
final File dotPackagesFile = new File(path.join('packages', 'flutter', '.packages'));
final File dotPackagesFile = new File(path.join('packages', 'flutter_localizations', '.packages'));
final bool dotPackagesExists = dotPackagesFile.existsSync();
if (!dotPackagesExists) {
......
......@@ -409,7 +409,7 @@ class DayPicker extends StatelessWidget {
Widget dayWidget = new Container(
decoration: decoration,
child: new Center(
child: new Text(day.toString(), style: itemStyle),
child: new Text(localizations.formatDecimal(day), style: itemStyle),
),
);
......
......@@ -114,6 +114,10 @@ abstract class MaterialLocalizations {
/// See also: https://material.io/guidelines/style/typography.html
TextTheme get localTextGeometry;
/// Formats [number] as a decimal, inserting locale-appropriate thousands
/// separators as necessary.
String formatDecimal(int number);
/// Formats [TimeOfDay.hour] in the given time of day according to the value
/// of [timeOfDayFormat].
String formatHour(TimeOfDay timeOfDay);
......@@ -314,7 +318,7 @@ class DefaultMaterialLocalizations implements MaterialLocalizations {
return null;
}
/// Formats an integer, inserting thousands separators as needed.
@override
String formatDecimal(int number) {
if (number > -1000 && number < 1000)
return number.toString();
......
......@@ -8,5 +8,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -184,6 +184,7 @@ const Map<String, dynamic> dateSymbols = const <String, dynamic>{
r'''{1} {0}''',
r'''{1} {0}'''
],
'ZERODIGIT': r'''٠''',
},
'de': const <String, dynamic>{
'NAME': r'''de''',
......@@ -899,6 +900,7 @@ const Map<String, dynamic> dateSymbols = const <String, dynamic>{
r'''{1}،‏ {0}''',
r'''{1}،‏ {0}'''
],
'ZERODIGIT': r'''۰''',
},
'fr': const <String, dynamic>{
'NAME': r'''fr''',
......@@ -1615,6 +1617,188 @@ const Map<String, dynamic> dateSymbols = const <String, dynamic>{
r'''{1} {0}'''
],
},
'ps': const <String, dynamic>{
'NAME': r'''ps''',
'ERAS': const <dynamic>[r'''له میلاد وړاندې''', r'''م.'''],
'ERANAMES': const <dynamic>[
r'''له میلاد څخه وړاندې''',
r'''له میلاد څخه وروسته'''
],
'NARROWMONTHS': const <dynamic>[
r'''1''',
r'''2''',
r'''3''',
r'''4''',
r'''5''',
r'''6''',
r'''7''',
r'''8''',
r'''9''',
r'''10''',
r'''11''',
r'''12'''
],
'STANDALONENARROWMONTHS': const <dynamic>[
r'''1''',
r'''2''',
r'''3''',
r'''4''',
r'''5''',
r'''6''',
r'''7''',
r'''8''',
r'''9''',
r'''10''',
r'''11''',
r'''12'''
],
'MONTHS': const <dynamic>[
r'''جنوري''',
r'''فبروري''',
r'''مارچ''',
r'''اپریل''',
r'''مۍ''',
r'''جون''',
r'''جولای''',
r'''اګست''',
r'''سپتمبر''',
r'''اکتوبر''',
r'''نومبر''',
r'''دسمبر'''
],
'STANDALONEMONTHS': const <dynamic>[
r'''جنوري''',
r'''فبروري''',
r'''مارچ''',
r'''اپریل''',
r'''مۍ''',
r'''جون''',
r'''جولای''',
r'''اګست''',
r'''سپتمبر''',
r'''اکتوبر''',
r'''نومبر''',
r'''دسمبر'''
],
'SHORTMONTHS': const <dynamic>[
r'''جنوري''',
r'''فبروري''',
r'''مارچ''',
r'''اپریل''',
r'''مۍ''',
r'''جون''',
r'''جولای''',
r'''اګست''',
r'''سپتمبر''',
r'''اکتوبر''',
r'''نومبر''',
r'''دسمبر'''
],
'STANDALONESHORTMONTHS': const <dynamic>[
r'''جنوري''',
r'''فبروري''',
r'''مارچ''',
r'''اپریل''',
r'''مۍ''',
r'''جون''',
r'''جولای''',
r'''اګست''',
r'''سپتمبر''',
r'''اکتوبر''',
r'''نومبر''',
r'''دسمبر'''
],
'WEEKDAYS': const <dynamic>[
r'''یکشنبه''',
r'''دوشنبه''',
r'''سه‌شنبه''',
r'''چهارشنبه''',
r'''پنجشنبه''',
r'''جمعه''',
r'''شنبه'''
],
'STANDALONEWEEKDAYS': const <dynamic>[
r'''یکشنبه''',
r'''دوشنبه''',
r'''سه‌شنبه''',
r'''چهارشنبه''',
r'''پنجشنبه''',
r'''جمعه''',
r'''شنبه'''
],
'SHORTWEEKDAYS': const <dynamic>[
r'''یکشنبه''',
r'''دوشنبه''',
r'''سه‌شنبه''',
r'''چهارشنبه''',
r'''پنجشنبه''',
r'''جمعه''',
r'''شنبه'''
],
'STANDALONESHORTWEEKDAYS': const <dynamic>[
r'''یکشنبه''',
r'''دوشنبه''',
r'''سه‌شنبه''',
r'''چهارشنبه''',
r'''پنجشنبه''',
r'''جمعه''',
r'''شنبه'''
],
'NARROWWEEKDAYS': const <dynamic>[
r'''S''',
r'''M''',
r'''T''',
r'''W''',
r'''T''',
r'''F''',
r'''S'''
],
'STANDALONENARROWWEEKDAYS': const <dynamic>[
r'''S''',
r'''M''',
r'''T''',
r'''W''',
r'''T''',
r'''F''',
r'''S'''
],
'SHORTQUARTERS': const <dynamic>[
r'''لومړۍ ربعه''',
r'''۲مه ربعه''',
r'''۳مه ربعه''',
r'''۴مه ربعه'''
],
'QUARTERS': const <dynamic>[
r'''لومړۍ ربعه''',
r'''۲مه ربعه''',
r'''۳مه ربعه''',
r'''۴مه ربعه'''
],
'AMPMS': const <dynamic>[r'''غ.م.''', r'''غ.و.'''],
'DATEFORMATS': const <dynamic>[
r'''EEEE د y د MMMM d''',
r'''د y د MMMM d''',
r'''y MMM d''',
r'''y/M/d'''
],
'TIMEFORMATS': const <dynamic>[
r'''H:mm:ss (zzzz)''',
r'''H:mm:ss (z)''',
r'''H:mm:ss''',
r'''H:mm'''
],
'AVAILABLEFORMATS': null,
'FIRSTDAYOFWEEK': 5,
'WEEKENDRANGE': const <dynamic>[3, 4],
'FIRSTWEEKCUTOFFDAY': 4,
'DATETIMEFORMATS': const <dynamic>[
r'''{1} {0}''',
r'''{1} {0}''',
r'''{1} {0}''',
r'''{1} {0}'''
],
'ZERODIGIT': r'''۰''',
},
'pt': const <String, dynamic>{
'NAME': r'''pt''',
'ERAS': const <dynamic>[r'''a.C.''', r'''d.C.'''],
......@@ -2749,6 +2933,52 @@ const Map<String, dynamic> datePatterns = const <String, dynamic>{
'zzzz': r'''zzzz''',
'ZZZZ': r'''ZZZZ''',
},
'ps': const <String, dynamic>{
'd': r'''d''',
'E': r'''ccc''',
'EEEE': r'''cccc''',
'LLL': r'''LLL''',
'LLLL': r'''LLLL''',
'M': r'''L''',
'Md': r'''M/d''',
'MEd': r'''MM-dd, EEE''',
'MMM': r'''LLL''',
'MMMd': r'''MMM d''',
'MMMEd': r'''MMM d, EEE''',
'MMMM': r'''LLLL''',
'MMMMd': r'''d MMMM''',
'MMMMEEEEd': r'''MMMM d, EEEE''',
'QQQ': r'''QQQ''',
'QQQQ': r'''QQQQ''',
'y': r'''y''',
'yM': r'''y/M''',
'yMd': r'''y-MM-dd''',
'yMEd': r'''y-MM-dd, EEE''',
'yMMM': r'''y MMM''',
'yMMMd': r'''y MMM d''',
'yMMMEd': r'''y MMM d, EEE''',
'yMMMM': r'''د y د MMMM''',
'yMMMMd': r'''د y د MMMM d''',
'yMMMMEEEEd': r'''EEEE د y د MMMM d''',
'yQQQ': r'''y QQQ''',
'yQQQQ': r'''y QQQQ''',
'H': r'''H''',
'Hm': r'''H:mm''',
'Hms': r'''H:mm:ss''',
'j': r'''H''',
'jm': r'''H:mm''',
'jms': r'''H:mm:ss''',
'jmv': r'''HH:mm v''',
'jmz': r'''HH:mm z''',
'jz': r'''H (z)''',
'm': r'''m''',
'ms': r'''mm:ss''',
's': r'''s''',
'v': r'''v''',
'z': r'''z''',
'zzzz': r'''zzzz''',
'ZZZZ': r'''ZZZZ''',
},
'pt': const <String, dynamic>{
'd': r'''d''',
'E': r'''ccc''',
......@@ -2841,6 +3071,52 @@ const Map<String, dynamic> datePatterns = const <String, dynamic>{
'zzzz': r'''zzzz''',
'ZZZZ': r'''ZZZZ''',
},
'sd': const <String, dynamic>{
'd': r'''d''',
'E': r'''ccc''',
'EEEE': r'''cccc''',
'LLL': r'''LLL''',
'LLLL': r'''LLLL''',
'M': r'''L''',
'Md': r'''M/d''',
'MEd': r'''EEE, M/d''',
'MMM': r'''LLL''',
'MMMd': r'''MMM d''',
'MMMEd': r'''EEE, MMM d''',
'MMMM': r'''LLLL''',
'MMMMd': r'''MMMM d''',
'MMMMEEEEd': r'''EEEE, MMMM d''',
'QQQ': r'''QQQ''',
'QQQQ': r'''QQQQ''',
'y': r'''y''',
'yM': r'''M/y''',
'yMd': r'''M/d/y''',
'yMEd': r'''EEE, M/d/y''',
'yMMM': r'''MMM y''',
'yMMMd': r'''MMM d, y''',
'yMMMEd': r'''EEE, MMM d, y''',
'yMMMM': r'''MMMM y''',
'yMMMMd': r'''MMMM d, y''',
'yMMMMEEEEd': r'''EEEE, MMMM d, y''',
'yQQQ': r'''QQQ y''',
'yQQQQ': r'''QQQQ y''',
'H': r'''HH''',
'Hm': r'''HH:mm''',
'Hms': r'''HH:mm:ss''',
'j': r'''h a''',
'jm': r'''h:mm a''',
'jms': r'''h:mm:ss a''',
'jmv': r'''h:mm a v''',
'jmz': r'''h:mm a z''',
'jz': r'''h a z''',
'm': r'''m''',
'ms': r'''mm:ss''',
's': r'''s''',
'v': r'''v''',
'z': r'''z''',
'zzzz': r'''zzzz''',
'ZZZZ': r'''ZZZZ''',
},
'ur': const <String, dynamic>{
'd': r'''d''',
'E': r'''ccc''',
......@@ -2865,7 +3141,7 @@ const Map<String, dynamic> datePatterns = const <String, dynamic>{
'yMMM': r'''MMM y''',
'yMMMd': r'''d MMM، y''',
'yMMMEd': r'''EEE، d MMM، y''',
'yMMMM': r'''y MMMM''',
'yMMMM': r'''MMMM y''',
'yMMMMd': r'''d MMMM، y''',
'yMMMMEEEEd': r'''EEEE، d MMMM، y''',
'yQQQ': r'''QQQ y''',
......
......@@ -8,9 +8,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
import 'package:intl/date_symbols.dart' as intl;
// TODO(yjbanov): remove internal import when https://github.com/dart-lang/intl/issues/145 is fixed.
// ignore: implementation_imports
import 'package:intl/src/date_format_internal.dart' as date_format_internal;
import 'package:intl/date_symbol_data_custom.dart' as date_symbol_data_custom;
import 'l10n/date_localizations.dart' as date_localizations;
import 'l10n/localizations.dart';
......@@ -184,9 +182,7 @@ class GlobalMaterialLocalizations implements MaterialLocalizations {
@override
int get firstDayOfWeekIndex => (_fullYearFormat.dateSymbols.FIRSTDAYOFWEEK + 1) % 7;
/// Formats a [number] using local decimal number format.
///
/// Inserts locale-appropriate thousands separator, if necessary.
@override
String formatDecimal(int number) {
return _decimalFormat.format(number);
}
......@@ -416,13 +412,14 @@ bool _dateIntlDataInitialized = false;
/// data. Subsequent invocations have no effect.
void _loadDateIntlDataIfNotLoaded() {
if (!_dateIntlDataInitialized) {
date_format_internal.initializeDatePatterns(() => date_localizations.datePatterns);
date_format_internal.initializeDateSymbols(() {
final Map<String, intl.DateSymbols> symbols = <String, intl.DateSymbols>{};
date_localizations.dateSymbols.forEach((String locale, dynamic data) {
symbols[locale] = new intl.DateSymbols.deserializeFromMap(data);
});
return symbols;
date_localizations.dateSymbols.forEach((String locale, dynamic data) {
assert(date_localizations.datePatterns.containsKey(locale));
final intl.DateSymbols symbols = new intl.DateSymbols.deserializeFromMap(data);
date_symbol_data_custom.initializeDateFormattingCustom(
locale: locale,
symbols: symbols,
patterns: date_localizations.datePatterns[locale],
);
});
_dateIntlDataInitialized = true;
}
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:intl/intl.dart' as intl;
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
......@@ -18,6 +20,7 @@ void main() {
});
group(DayPicker, () {
final intl.NumberFormat arabicNumbers = new intl.NumberFormat('0', 'ar');
final Map<Locale, Map<String, dynamic>> testLocales = <Locale, Map<String, dynamic>>{
// Tests the default.
const Locale('en', 'US'): <String, dynamic>{
......@@ -34,14 +37,11 @@ void main() {
'expectedMonthYearHeader': 'сентябрь 2017 г.',
},
// Tests RTL.
// TODO: change to Arabic numerals when these are fixed:
// TODO: https://github.com/dart-lang/intl/issues/143
// TODO: https://github.com/flutter/flutter/issues/12289
const Locale('ar', 'AR'): <String, dynamic>{
'textDirection': TextDirection.rtl,
'expectedDaysOfWeek': <String>['ح', 'ن', 'ث', 'ر', 'خ', 'ج', 'س'],
'expectedDaysOfMonth': new List<String>.generate(30, (int i) => '${i + 1}'),
'expectedMonthYearHeader': 'سبتمبر 2017',
'expectedDaysOfMonth': new List<String>.generate(30, (int i) => '${arabicNumbers.format(i + 1)}'),
'expectedMonthYearHeader': 'سبتمبر ٢٠١٧',
},
};
......
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