Unverified Commit 83a74e11 authored by gaaclarke's avatar gaaclarke Committed by GitHub

Started caching results from iana. (#53286)

parent 8a902352
......@@ -2,7 +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 'dart:io';
import 'package:args/args.dart' as argslib;
......@@ -13,7 +12,7 @@ import '../gen_l10n.dart';
import '../gen_l10n_types.dart';
import '../localizations_utils.dart';
Future<void> main(List<String> arguments) async {
void main(List<String> arguments) {
final argslib.ArgParser parser = argslib.ArgParser();
parser.addFlag(
'help',
......@@ -80,7 +79,7 @@ Future<void> main(List<String> arguments) async {
exit(0);
}
await precacheLanguageAndRegionTags();
precacheLanguageAndRegionTags();
final String arbPathString = results['arb-dir'] as String;
final String outputFileString = results['output-localization-file'] as String;
......
......@@ -40,7 +40,6 @@
// dart dev/tools/localization/bin/gen_localizations.dart --overwrite
// ```
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
......@@ -480,7 +479,7 @@ String generateGetter(String key, String value, Map<String, dynamic> attributes,
$type get $key => $value;''';
}
Future<void> main(List<String> rawArgs) async {
void main(List<String> rawArgs) {
checkCwdIsRepoRoot('gen_localizations');
final GeneratorOptions options = parseArgs(rawArgs);
......@@ -499,7 +498,7 @@ Future<void> main(List<String> rawArgs) async {
exitWithError('$exception');
}
await precacheLanguageAndRegionTags();
precacheLanguageAndRegionTags();
// Maps of locales to resource key/value pairs for Material ARBs.
final Map<LocaleInfo, Map<String, String>> materialLocaleToResources = <LocaleInfo, Map<String, String>>{};
......
// Copyright 2014 The Flutter 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:async';
import 'dart:convert';
import 'dart:io';
const String registry = 'https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry';
/// A script to generate a Dart cache of https://www.iana.org. This should be
/// run occasionally. It was created since iana.org was found to be flakey.
///
/// To execute: dart gen_subtag_registry.dart > language_subtag_registry.dart
Future<void> main() async {
final HttpClient client = HttpClient();
final HttpClientRequest request = await client.getUrl(Uri.parse(registry));
final HttpClientResponse response = await request.close();
final String body = (await response.cast<List<int>>().transform<String>(utf8.decoder).toList()).join('');
print('''// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Cache of $registry.
const String languageSubtagRegistry = \'\'\'$body\'\'\';''');
client.close(force: true);
}
This diff is collapsed.
......@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:args/args.dart' as argslib;
import 'package:meta/meta.dart';
import 'language_subtag_registry.dart';
typedef HeaderGenerator = String Function(String regenerateInstructions);
typedef ConstructorGenerator = String Function(LocaleInfo locale);
......@@ -264,8 +265,6 @@ class GeneratorOptions {
final bool cupertinoOnly;
}
const String registry = 'https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry';
// See also //master/tools/gen_locale.dart in the engine repo.
Map<String, List<String>> _parseSection(String section) {
final Map<String, List<String>> result = <String, List<String>>{};
......@@ -297,13 +296,9 @@ const String kParentheticalPrefix = ' (';
/// Prepares the data for the [describeLocale] method below.
///
/// The data is obtained from the official IANA registry.
Future<void> precacheLanguageAndRegionTags() async {
final HttpClient client = HttpClient();
final HttpClientRequest request = await client.getUrl(Uri.parse(registry));
final HttpClientResponse response = await request.close();
final String body = (await response.cast<List<int>>().transform<String>(utf8.decoder).toList()).join('');
client.close(force: true);
final List<Map<String, List<String>>> sections = body.split('%%').skip(1).map<Map<String, List<String>>>(_parseSection).toList();
void precacheLanguageAndRegionTags() {
final List<Map<String, List<String>>> sections =
languageSubtagRegistry.split('%%').skip(1).map<Map<String, List<String>>>(_parseSection).toList();
for (final Map<String, List<String>> section in sections) {
assert(section.containsKey('Type'), section.toString());
final String type = section['Type'].single;
......
......@@ -47,11 +47,11 @@ void _standardFlutterDirectoryL10nSetup(FileSystem fs) {
void main() {
MemoryFileSystem fs;
setUp(() async {
setUp(() {
fs = MemoryFileSystem(
style: Platform.isWindows ? FileSystemStyle.windows : FileSystemStyle.posix
);
await precacheLanguageAndRegionTags();
precacheLanguageAndRegionTags();
});
group('Setters', () {
......
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