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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
45
dev/tools/localizations_utils.dart
Normal file
45
dev/tools/localizations_utils.dart
Normal file
@@ -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<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;
|
||||
}
|
||||
Reference in New Issue
Block a user