Skip to content

Commit

Permalink
flutter_localization optional package (flutter#12410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Muller committed Oct 11, 2017
1 parent f07170b commit c3d56b1
Show file tree
Hide file tree
Showing 68 changed files with 1,747 additions and 1,187 deletions.
2 changes: 1 addition & 1 deletion dev/automated_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/benchmarks/complex_layout/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/benchmarks/microbenchmarks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/bots/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
5 changes: 3 additions & 2 deletions dev/bots/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ Future<Null> _verifyInternationalizations() async {
dart,
<String>[
path.join('dev', 'tools', 'gen_localizations.dart'),
path.join('packages', 'flutter', 'lib', 'src', 'material', 'i18n'),
path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'),
'material'
],
workingDirectory: flutterRoot,
);

final String localizationsFile = path.join('packages', 'flutter', 'lib', 'src', 'material', 'i18n', 'localizations.dart');
final String localizationsFile = path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n', 'localizations.dart');

final EvalResult sourceContents = await _evalCommand(
'cat',
Expand Down Expand Up @@ -156,6 +156,7 @@ Future<Null> _runTests() async {

// Run tests.
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_localizations'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_driver'));
await _runFlutterTest(path.join(flutterRoot, 'packages', 'flutter_test'));
await _pubRunTest(path.join(flutterRoot, 'packages', 'flutter_tools'));
Expand Down
2 changes: 1 addition & 1 deletion dev/devicelab/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dev_dependencies:

archive: 1.0.31 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
boolean_selector: 1.0.2 # TRANSITIVE DEPENDENCY
browser: 0.10.0+2 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/integration_tests/channels/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/integration_tests/flavors/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/integration_tests/platform_interaction/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/integration_tests/ui/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
boolean_selector: 1.0.2 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/manual_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
path: 1.4.2

async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/catalog/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_gallery/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
convert: 2.0.1 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_view/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/layers/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_channel/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_channel_swift/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_view/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
5 changes: 4 additions & 1 deletion examples/stocks/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:flutter/rendering.dart' show
debugPaintLayerBordersEnabled,
debugPaintPointersEnabled,
debugRepaintRainbowEnabled;
import 'package:flutter_localizations/flutter_localizations.dart';

import 'stock_data.dart';
import 'stock_home.dart';
Expand Down Expand Up @@ -118,8 +119,10 @@ class StocksAppState extends State<StocksApp> {
return new MaterialApp(
title: 'Stocks',
theme: theme,
localizationsDelegates: <_StocksLocalizationsDelegate>[
localizationsDelegates: <LocalizationsDelegate<dynamic>>[
new _StocksLocalizationsDelegate(),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: const <Locale>[
const Locale('en', 'US'),
Expand Down
4 changes: 3 additions & 1 deletion examples/stocks/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: stocks
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: 0.15.1
intl_translation: 0.15.0
http: 0.11.3+14
Expand All @@ -15,7 +17,7 @@ dev_dependencies:

args: 0.13.7 # TRANSITIVE DEPENDENCY
async: 1.13.3 # TRANSITIVE DEPENDENCY
barback: 0.15.2+12 # TRANSITIVE DEPENDENCY
barback: 0.15.2+13 # TRANSITIVE DEPENDENCY
charcode: 1.1.1 # TRANSITIVE DEPENDENCY
cli_util: 0.1.2+1 # TRANSITIVE DEPENDENCY
collection: 1.14.3 # TRANSITIVE DEPENDENCY
Expand Down
15 changes: 1 addition & 14 deletions packages/flutter/lib/src/material/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/rendering.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
Expand All @@ -26,17 +24,6 @@ const TextStyle _errorTextStyle = const TextStyle(
decorationStyle: TextDecorationStyle.double
);

class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
const _MaterialLocalizationsDelegate();

@override
Future<MaterialLocalizations> load(Locale locale) => DefaultMaterialLocalizations.load(locale);

@override
bool shouldReload(_MaterialLocalizationsDelegate old) => false;
}


/// An application that uses material design.
///
/// A convenience widget that wraps a number of widgets that are commonly
Expand Down Expand Up @@ -463,7 +450,7 @@ class _MaterialAppState extends State<MaterialApp> {
Iterable<LocalizationsDelegate<dynamic>> get _localizationsDelegates sync* {
if (widget.localizationsDelegates != null)
yield* widget.localizationsDelegates;
yield const _MaterialLocalizationsDelegate();
yield DefaultMaterialLocalizations.delegate;
}

RectTween _createRectTween(Rect begin, Rect end) {
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/material/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ class DayPicker extends StatelessWidget {
List<Widget> _getDayHeaders(TextStyle headerStyle, MaterialLocalizations localizations) {
final List<Widget> result = <Widget>[];
for (int i = localizations.firstDayOfWeekIndex; true; i = (i + 1) % 7) {
final String weekDay = localizations.narrowWeekDays[i];
result.add(new Center(child: new Text(weekDay, style: headerStyle)));
final String weekday = localizations.narrowWeekdays[i];
result.add(new Center(child: new Text(weekday, style: headerStyle)));
if (i == (localizations.firstDayOfWeekIndex - 1) % 7)
break;
}
Expand Down Expand Up @@ -350,19 +350,19 @@ class DayPicker extends StatelessWidget {
/// - [DateTime.weekday] provides a 1-based index into days of week, with 1
/// falling on Monday.
/// - [MaterialLocalizations.firstDayOfWeekIndex] provides a 0-based index
/// into the [MaterialLocalizations.narrowWeekDays] list.
/// - [MaterialLocalizations.narrowWeekDays] list provides localized names of
/// into the [MaterialLocalizations.narrowWeekdays] list.
/// - [MaterialLocalizations.narrowWeekdays] list provides localized names of
/// days of week, always starting with Sunday and ending with Saturday.
int _computeFirstDayOffset(int year, int month, MaterialLocalizations localizations) {
// 0-based day of week, with 0 representing Monday.
final int weekDayFromMonday = new DateTime(year, month).weekday - 1;
final int weekdayFromMonday = new DateTime(year, month).weekday - 1;
// 0-based day of week, with 0 representing Sunday.
final int firstDayOfWeekFromSunday = localizations.firstDayOfWeekIndex;
// firstDayOfWeekFromSunday recomputed to be Monday-based
final int firstDayOfWeekFromMonday = (firstDayOfWeekFromSunday - 1) % 7;
// Number of days between the first day of week appearing on the calendar,
// and the day corresponding to the 1-st of the month.
return (weekDayFromMonday - firstDayOfWeekFromMonday) % 7;
return (weekdayFromMonday - firstDayOfWeekFromMonday) % 7;
}

@override
Expand Down

0 comments on commit c3d56b1

Please sign in to comment.