1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:convert';
6import 'dart:io';
7
8const String registry =
9 'https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry';
10
11/// A script to generate a Dart cache of https://www.iana.org. This should be
12/// run occasionally. It was created since iana.org was found to be flaky.
13///
14/// To execute: dart gen_subtag_registry.dart > language_subtag_registry.dart
15Future<void> main() async {
16 final HttpClient client = HttpClient();
17 final HttpClientRequest request = await client.getUrl(Uri.parse(registry));
18 final HttpClientResponse response = await request.close();
19 final String body = (await response.cast<List<int>>().transform<String>(utf8.decoder).toList())
20 .join();
21 final File subtagRegistry = File('../language_subtag_registry.dart');
22 final File subtagRegistryFlutterTools = File(
23 '../../../../packages/flutter_tools/lib/src/localizations/language_subtag_registry.dart',
24 );
25
26 final String content =
27 '''
28// Copyright 2014 The Flutter Authors. All rights reserved.
29// Use of this source code is governed by a BSD-style license that can be
30// found in the LICENSE file.
31
32/// Cache of $registry.
33const String languageSubtagRegistry = \'\'\'$body\'\'\';''';
34
35 subtagRegistry.writeAsStringSync(content);
36 subtagRegistryFlutterTools.writeAsStringSync(content);
37
38 client.close(force: true);
39}
40