Unverified Commit 41bd66f2 authored by Yegor's avatar Yegor Committed by GitHub

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
parent e43eab65
......@@ -57,8 +57,6 @@ Future<Null> _verifyInternationalizations() async {
dart,
<String>[
path.join('dev', 'tools', 'gen_localizations.dart'),
path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'),
'material'
],
workingDirectory: flutterRoot,
);
......
......@@ -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<Null> main(List<String> 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<Null> main(List<String> 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<String> _materialLocales() sync* {
final RegExp filenameRE = new RegExp(r'.*_(\w+)\.arb$');
final Directory materialLocalizationsDirectory = new Directory(path.join('packages', 'flutter_localizations', 'lib', 'src', 'l10n'));
......
......@@ -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<String> args) {
if (args.length != 2)
stderr.writeln('Usage: dart gen_localizations.dart directory prefix');
void main(List<String> 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<String> 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);
}
}
// 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<String> 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;
}
......@@ -3071,52 +3071,6 @@ 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''',
......
......@@ -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<String, Map<String, String>> localizations = const <String, Map<String
'selectAllButtonLabel': r'ВЫБРАТЬ ВСЁ',
'viewLicensesButtonLabel': r'ПРОСМОТРЕТЬ ЛИЦЕНЗИИ',
},
'sd': const <String, String>{
'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 <String, String>{
'scriptCategory': r'tall',
'timeOfDayFormat': r'h:mm a',
......
{
"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": "لائسنس ڏسو"
}
......@@ -441,7 +441,6 @@ class _MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocal
'ps', // Pashto
'pt', // Portugese
'ru', // Russian
'sd', // Sindhi
'ur', // Urdu
'zh', // Simplified Chinese
];
......
......@@ -36,7 +36,6 @@ class GlobalWidgetsLocalizations implements WidgetsLocalizations {
'fa', // Farsi
'he', // Hebrew
'ps', // Pashto
'sd', // Sindhi
'ur', // Urdu
];
......
......@@ -20,7 +20,6 @@ void main() {
'ps', // Pashto
'pt', // Portugese
'ru', // Russian
'sd', // Sindhi
'ur', // Urdu
'zh', // Chinese (simplified)
];
......
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