From 41bd66f2100e92443f523e0d1bd9e467ddedb530 Mon Sep 17 00:00:00 2001 From: Yegor Date: Tue, 31 Oct 2017 20:23:58 -0700 Subject: [PATCH] remove locale "sd" (not supported by ICU/CLDR); unify localizations script options (#12803) * remove locale "sd" (not supported by ICU/CLDR); unify localizations scripts CLI * address comments --- dev/bots/test.dart | 2 - dev/tools/gen_date_localizations.dart | 28 ++++----- dev/tools/gen_localizations.dart | 60 +++++++++++++------ dev/tools/localizations_utils.dart | 45 ++++++++++++++ .../lib/src/l10n/date_localizations.dart | 46 -------------- .../lib/src/l10n/localizations.dart | 29 +-------- .../lib/src/l10n/material_sd.arb | 29 --------- .../lib/src/material_localizations.dart | 1 - .../lib/src/widgets_localizations.dart | 1 - .../test/translations_test.dart | 1 - 10 files changed, 98 insertions(+), 144 deletions(-) create mode 100644 dev/tools/localizations_utils.dart delete mode 100644 packages/flutter_localizations/lib/src/l10n/material_sd.arb diff --git a/dev/bots/test.dart b/dev/bots/test.dart index c3fffa71b2..e2b8ec8c92 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -57,8 +57,6 @@ Future _verifyInternationalizations() async { dart, [ path.join('dev', 'tools', 'gen_localizations.dart'), - path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'), - 'material' ], workingDirectory: flutterRoot, ); diff --git a/dev/tools/gen_date_localizations.dart b/dev/tools/gen_date_localizations.dart index 8c0023e855..e93ecf493d 100644 --- a/dev/tools/gen_date_localizations.dart +++ b/dev/tools/gen_date_localizations.dart @@ -6,9 +6,11 @@ /// package for the subset of locales supported by the flutter_localizations /// package. /// -/// The extracted data is written into lib/src/l10n/date_localizations.dart. +/// The extracted data is written into packages/flutter_localizations/lib/src/l10n/date_localizations.dart. /// -/// Usage: +/// ## Usage +/// +/// Run this program from the root of the git repository. /// /// The following outputs the generated Dart code to the console as a dry run: /// @@ -27,27 +29,22 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:args/args.dart' as args; import 'package:path/path.dart' as path; +import 'localizations_utils.dart'; + const String _kCommandName = 'gen_date_localizations.dart'; Future main(List rawArgs) async { - final bool writeToFile = (new args.ArgParser()..addFlag('overwrite', abbr: 'w', defaultsTo: false)).parse(rawArgs)['overwrite']; - final bool isRepoRoot = new Directory('.git').existsSync(); + checkCwdIsRepoRoot(_kCommandName); - if (!isRepoRoot) { - _fatal( - '$_kCommandName must be run from the root of the Flutter repository. The ' - 'current working directory is: ${Directory.current.path}' - ); - } + final bool writeToFile = parseArgs(rawArgs).writeToFile; final File dotPackagesFile = new File(path.join('packages', 'flutter_localizations', '.packages')); final bool dotPackagesExists = dotPackagesFile.existsSync(); if (!dotPackagesExists) { - _fatal( + fatal( 'File not found: ${dotPackagesFile.path}. $_kCommandName must be run ' 'after a successful "flutter update-packages".' ); @@ -59,7 +56,7 @@ Future main(List rawArgs) async { .firstWhere( (String line) => line.startsWith('intl:'), orElse: () { - _fatal('intl dependency not found in ${dotPackagesFile.path}'); + fatal('intl dependency not found in ${dotPackagesFile.path}'); }, ) .split(':') @@ -140,11 +137,6 @@ String _jsonToMap(dynamic json) { throw 'Unsupported JSON type ${json.runtimeType} of value $json.'; } -void _fatal(String message) { - stderr.writeln(message); - exit(1); -} - Iterable _materialLocales() sync* { final RegExp filenameRE = new RegExp(r'.*_(\w+)\.arb$'); final Directory materialLocalizationsDirectory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n')); diff --git a/dev/tools/gen_localizations.dart b/dev/tools/gen_localizations.dart index d2558ebf01..8bdda80885 100644 --- a/dev/tools/gen_localizations.dart +++ b/dev/tools/gen_localizations.dart @@ -2,30 +2,47 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Given a directory that contains localized ".arb" (application resource -// bundle) files, generates a Dart "localizations" Map definition that combines +// This program generates a Dart "localizations" Map definition that combines // the contents of the arb files. The map can be used to lookup a localized -// string: localizations[localeString][resourceId]. +// string: `localizations[localeString][resourceId]`. // -// See *.arb and localizations.dart in packages/flutter/lib/src/material/i18n/. +// The *.arb files are in packages/flutter_localizations/lib/src/l10n. // // The arb (JSON) format files must contain a single map indexed by locale. // Each map value is itself a map with resource identifier keys and localized // resource string values. // -// The arb filenames are assumed to end in "prefix_lc.arb" or "prefix_lc_cc.arb", -// where prefix is the 2nd command line argument, lc is a language code and cc -// is the country code. In most cases both codes are just two characters. A typical -// filename would be "material_en.arb". +// The arb filenames are expected to have the form "material_(\w+)\.arb", where +// the group following "_" identifies the language code and the country code, +// e.g. "material_en.arb" or "material_en_GB.arb". In most cases both codes are +// just two characters. // // This app is typically run by hand when a module's .arb files have been // updated. // -// Usage: dart gen_localizations.dart directory prefix +// ## Usage +// +// Run this program from the root of the git repository. +// +// The following outputs the generated Dart code to the console as a dry run: +// +// ``` +// dart dev/tools/gen_localizations.dart +// ``` +// +// If the data looks good, use the `-w` option to overwrite the +// packages/flutter_localizations/lib/src/l10n/localizations.dart file: +// +// ``` +// dart dev/tools/gen_localizations.dart --overwrite +// ``` import 'dart:convert' show JSON; import 'dart:io'; +import 'package:path/path.dart' as pathlib; + +import 'localizations_utils.dart'; import 'localizations_validator.dart'; const String outputHeader = ''' @@ -114,17 +131,16 @@ void processBundle(File file, String locale) { } } -void main(List args) { - if (args.length != 2) - stderr.writeln('Usage: dart gen_localizations.dart directory prefix'); +void main(List rawArgs) { + checkCwdIsRepoRoot('gen_localizations'); + final GeneratorOptions options = parseArgs(rawArgs); // filenames are assumed to end in "prefix_lc.arb" or "prefix_lc_cc.arb", where prefix // is the 2nd command line argument, lc is a language code and cc is the country // code. In most cases both codes are just two characters. - final Directory directory = new Directory(args[0]); - final String prefix = args[1]; - final RegExp filenameRE = new RegExp('${prefix}_(\\w+)\\.arb\$'); + final Directory directory = new Directory(pathlib.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n')); + final RegExp filenameRE = new RegExp(r'material_(\w+)\.arb$'); for (FileSystemEntity entity in directory.listSync()) { final String path = entity.path; @@ -135,7 +151,15 @@ void main(List args) { } validateLocalizations(localeToResources, localeToResourceAttributes); - final String regenerate = 'dart dev/tools/gen_localizations.dart ${directory.path} ${args[1]}'; - print(outputHeader.replaceFirst('@(regenerate)', regenerate)); - print(generateLocalizationsMap()); + final String regenerate = 'dart dev/tools/gen_localizations.dart --overwrite'; + final StringBuffer buffer = new StringBuffer(); + buffer.writeln(outputHeader.replaceFirst('@(regenerate)', regenerate)); + buffer.writeln(generateLocalizationsMap()); + + if (options.writeToFile) { + final File localizationsFile = new File(pathlib.join(directory.path, 'localizations.dart')); + localizationsFile.writeAsStringSync('$buffer'); + } else { + print(buffer); + } } diff --git a/dev/tools/localizations_utils.dart b/dev/tools/localizations_utils.dart new file mode 100644 index 0000000000..a2825e9d81 --- /dev/null +++ b/dev/tools/localizations_utils.dart @@ -0,0 +1,45 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:io'; + +import 'package:args/args.dart' as argslib; +import 'package:meta/meta.dart'; + +void fatal(String message) { + stderr.writeln(message); + exit(1); +} + +void checkCwdIsRepoRoot(String commandName) { + final bool isRepoRoot = new Directory('.git').existsSync(); + + if (!isRepoRoot) { + fatal( + '$commandName must be run from the root of the Flutter repository. The ' + 'current working directory is: ${Directory.current.path}' + ); + } +} + +GeneratorOptions parseArgs(List rawArgs) { + final argslib.ArgParser argParser = new argslib.ArgParser() + ..addFlag( + 'overwrite', + abbr: 'w', + defaultsTo: false, + ); + final argslib.ArgResults args = argParser.parse(rawArgs); + final bool writeToFile = args['overwrite']; + + return new GeneratorOptions(writeToFile: writeToFile); +} + +class GeneratorOptions { + GeneratorOptions({ + @required this.writeToFile, + }); + + final bool writeToFile; +} diff --git a/packages/flutter_localizations/lib/src/l10n/date_localizations.dart b/packages/flutter_localizations/lib/src/l10n/date_localizations.dart index e278edd638..bfabb84ca1 100644 --- a/packages/flutter_localizations/lib/src/l10n/date_localizations.dart +++ b/packages/flutter_localizations/lib/src/l10n/date_localizations.dart @@ -3071,52 +3071,6 @@ const Map datePatterns = const { 'zzzz': r'''zzzz''', 'ZZZZ': r'''ZZZZ''', }, - 'sd': const { - '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 { 'd': r'''d''', 'E': r'''ccc''', diff --git a/packages/flutter_localizations/lib/src/l10n/localizations.dart b/packages/flutter_localizations/lib/src/l10n/localizations.dart index 29ec474bf9..586f2c475b 100644 --- a/packages/flutter_localizations/lib/src/l10n/localizations.dart +++ b/packages/flutter_localizations/lib/src/l10n/localizations.dart @@ -4,7 +4,7 @@ // This file has been automatically generated. Please do not edit it manually. // To regenerate the file, use: -// dart dev/tools/gen_localizations.dart packages/flutter_localizations/lib/src/l10n material +// dart dev/tools/gen_localizations.dart --overwrite /// Maps from [Locale.languageCode] to a map that contains the localized strings /// for that locale. @@ -366,33 +366,6 @@ const Map> localizations = const { - 'scriptCategory': r'tall', - 'timeOfDayFormat': r'HH:mm', - 'openAppDrawerTooltip': r'اوپن جي مينڊيٽ مينيو', - 'backButtonTooltip': r'پوئتي', - 'closeButtonTooltip': r'بند ڪريو', - 'nextMonthTooltip': r'ايندڙ مهيني', - 'previousMonthTooltip': r'پويون مهينو', - 'nextPageTooltip': r'اڳيون پيج', - 'previousPageTooltip': r'پويون صفحو', - 'showMenuTooltip': r'ڏيکاريو', - 'aboutListTileTitle': r'$applicationName بابت', - 'licensesPageTitle': r'لائسنس', - 'pageRowsInfoTitle': r'$firstRow–$lastRow جي $rowCount', - 'pageRowsInfoTitleApproximate': r'$firstRow–$lastRow کان $rowCount تقريبن', - 'rowsPerPageTitle': r'رني پاسي وارو صفحو', - 'selectedRowCountTitleOther': r'$selectedRowCount شيون چونڊيل', - 'cancelButtonLabel': r'منسوخ ڪيو', - 'closeButtonLabel': r'بند ڪريو', - 'continueButtonLabel': r'جاري رکو', - 'copyButtonLabel': r'ڪاپي', - 'cutButtonLabel': r'پٽي', - 'okButtonLabel': r'ٺيڪ آهي', - 'pasteButtonLabel': r'پيسٽ ڪريو', - 'selectAllButtonLabel': r'سڀ چونڊيو', - 'viewLicensesButtonLabel': r'لائسنس ڏسو', - }, 'ur': const { 'scriptCategory': r'tall', 'timeOfDayFormat': r'h:mm a', diff --git a/packages/flutter_localizations/lib/src/l10n/material_sd.arb b/packages/flutter_localizations/lib/src/l10n/material_sd.arb deleted file mode 100644 index 3d2c115332..0000000000 --- a/packages/flutter_localizations/lib/src/l10n/material_sd.arb +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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" }, - "openAppDrawerTooltip": "اوپن جي مينڊيٽ مينيو", - "backButtonTooltip": "پوئتي", - "closeButtonTooltip": "بند ڪريو", - "nextMonthTooltip": "ايندڙ مهيني", - "previousMonthTooltip": "پويون مهينو", - "nextPageTooltip": "اڳيون پيج", - "previousPageTooltip": "پويون صفحو", - "showMenuTooltip": "ڏيکاريو", - "aboutListTileTitle": "$applicationName بابت", - "licensesPageTitle": "لائسنس", - "pageRowsInfoTitle": "$firstRow–$lastRow جي $rowCount", - "pageRowsInfoTitleApproximate": "$firstRow–$lastRow کان $rowCount تقريبن", - "rowsPerPageTitle": "رني پاسي وارو صفحو", - "selectedRowCountTitleOther": "$selectedRowCount شيون چونڊيل", - "cancelButtonLabel": "منسوخ ڪيو", - "closeButtonLabel": "بند ڪريو", - "continueButtonLabel": "جاري رکو", - "copyButtonLabel": "ڪاپي", - "cutButtonLabel": "پٽي", - "okButtonLabel": "ٺيڪ آهي", - "pasteButtonLabel": "پيسٽ ڪريو", - "selectAllButtonLabel": "سڀ چونڊيو", - "viewLicensesButtonLabel": "لائسنس ڏسو" -} diff --git a/packages/flutter_localizations/lib/src/material_localizations.dart b/packages/flutter_localizations/lib/src/material_localizations.dart index 6540440251..4825451f09 100644 --- a/packages/flutter_localizations/lib/src/material_localizations.dart +++ b/packages/flutter_localizations/lib/src/material_localizations.dart @@ -441,7 +441,6 @@ class _MaterialLocalizationsDelegate extends LocalizationsDelegate