mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
[Gallery] Add Travis CI check that l10n command has been run for the gallery (#263)
* Add command to grind to verify that l10n command has ben run
This commit is contained in:
@@ -65,7 +65,7 @@ for more details):
|
||||
flutter pub run grinder l10n
|
||||
```
|
||||
|
||||
To generate code segments (see separate [README](codeviewer_cli/README.md) for
|
||||
To generate code segments (see separate [README](gallery/tool/codeviewer_cli/README.md) for
|
||||
more details):
|
||||
```
|
||||
flutter pub run grinder update-code-segments
|
||||
|
||||
@@ -47,10 +47,32 @@ Future<void> generateLocalizations() async {
|
||||
@Task('Transform arb to xml for English')
|
||||
@Depends(generateLocalizations)
|
||||
Future<void> l10n() async {
|
||||
final l10nPath = path.join(Directory.current.parent.path, 'l10n_cli');
|
||||
await pubGet(directory: l10nPath);
|
||||
final l10nPath =
|
||||
path.join(Directory.current.path, 'tool', 'l10n_cli', 'main.dart');
|
||||
Dart.run(l10nPath);
|
||||
}
|
||||
|
||||
Dart.run(path.join(l10nPath, 'bin', 'main.dart'));
|
||||
@Task('Verify xml localizations')
|
||||
Future<void> verifyL10n() async {
|
||||
final l10nPath =
|
||||
path.join(Directory.current.path, 'tool', 'l10n_cli', 'main.dart');
|
||||
|
||||
// Run the tool to transform arb to xml, and write the output to stdout.
|
||||
final xmlOutput = Dart.run(l10nPath, arguments: ['--dry-run'], quiet: true);
|
||||
|
||||
// Read the original xml file.
|
||||
final xmlPath =
|
||||
path.join(Directory.current.path, 'lib', 'l10n', 'intl_en_US.xml');
|
||||
final expectedXmlOutput = await File(xmlPath).readAsString();
|
||||
|
||||
if (xmlOutput.trim() != expectedXmlOutput.trim()) {
|
||||
stderr.writeln(
|
||||
'The contents of $xmlPath are different from that produced by '
|
||||
'l10n_cli. Did you forget to run `flutter pub run grinder '
|
||||
'l10n` after updating an .arb file?',
|
||||
);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Task('Update code segments')
|
||||
|
||||
4
gallery/gallery/tool/l10n_cli/README.md
Normal file
4
gallery/gallery/tool/l10n_cli/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# l10n
|
||||
|
||||
A command-line application that converts .arb files to .xml files for
|
||||
translation consumption.
|
||||
@@ -37,24 +37,29 @@ String _escapeXml(String xml) {
|
||||
}
|
||||
|
||||
/// Processes the XML files.
|
||||
Future<void> englishArbsToXmls() async {
|
||||
Future<void> englishArbsToXmls({bool isDryRun = false}) async {
|
||||
IOSink output =
|
||||
isDryRun ? stdout : File('$_l10nDir/intl_en_US.xml').openWrite();
|
||||
await generateXmlFromArb(
|
||||
inputArb: File('$_l10nDir/intl_en_US.arb'),
|
||||
outputXml: File('$_l10nDir/intl_en_US.xml'),
|
||||
outputXml: output,
|
||||
xmlHeader: _intlHeader,
|
||||
);
|
||||
await output.close();
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
Future<void> generateXmlFromArb({
|
||||
File inputArb,
|
||||
File outputXml,
|
||||
IOSink outputXml,
|
||||
String xmlHeader,
|
||||
}) async {
|
||||
final Map<String, dynamic> bundle = jsonDecode(await inputArb.readAsString());
|
||||
final Map<String, dynamic> bundle =
|
||||
jsonDecode(await inputArb.readAsString()) as Map<String, dynamic>;
|
||||
|
||||
String translationFor(String key) {
|
||||
assert(bundle[key] != null);
|
||||
return _escapeXml(bundle[key]);
|
||||
return _escapeXml(bundle[key] as String);
|
||||
}
|
||||
|
||||
final xml = StringBuffer(xmlHeader);
|
||||
@@ -70,9 +75,9 @@ Future<void> generateXmlFromArb({
|
||||
|
||||
final resourceId = key.substring(1);
|
||||
final name = _escapeXml(resourceId);
|
||||
final Map<String, dynamic> metaInfo = bundle[key];
|
||||
final metaInfo = bundle[key] as Map<String, dynamic>;
|
||||
assert(metaInfo != null && metaInfo['description'] != null);
|
||||
var description = _escapeXml(metaInfo['description']);
|
||||
var description = _escapeXml(metaInfo['description'] as String);
|
||||
|
||||
if (metaInfo.containsKey('plural')) {
|
||||
// Generate a plurals resource element formatted like this:
|
||||
@@ -110,8 +115,8 @@ Future<void> generateXmlFromArb({
|
||||
// description's 'parameters' value, are replaced with printf positional
|
||||
// string arguments, like "%1$s".
|
||||
var translation = translationFor(resourceId);
|
||||
assert(metaInfo['parameters'].trim().isNotEmpty);
|
||||
final parameters = metaInfo['parameters']
|
||||
assert((metaInfo['parameters'] as String).trim().isNotEmpty);
|
||||
final parameters = (metaInfo['parameters'] as String)
|
||||
.split(',')
|
||||
.map<String>((s) => s.trim())
|
||||
.toList();
|
||||
@@ -139,6 +144,5 @@ Future<void> generateXmlFromArb({
|
||||
}
|
||||
}
|
||||
xml.writeln('</resources>');
|
||||
|
||||
await outputXml.writeAsString(xml.toString());
|
||||
outputXml.write(xml.toString());
|
||||
}
|
||||
17
gallery/gallery/tool/l10n_cli/main.dart
Normal file
17
gallery/gallery/tool/l10n_cli/main.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/args.dart';
|
||||
|
||||
import 'l10n_cli.dart' as l10n_cli;
|
||||
|
||||
void main(List<String> arguments) {
|
||||
final parser = ArgParser()
|
||||
..addFlag(
|
||||
'dry-run',
|
||||
help: 'Write the output to stdout.',
|
||||
);
|
||||
final argResults = parser.parse(arguments);
|
||||
l10n_cli.englishArbsToXmls(isDryRun: argResults['dry-run'] as bool);
|
||||
}
|
||||
13
gallery/l10n_cli/.gitignore
vendored
13
gallery/l10n_cli/.gitignore
vendored
@@ -1,13 +0,0 @@
|
||||
# Files and directories created by pub
|
||||
.dart_tool/
|
||||
.packages
|
||||
# Remove the following pattern if you wish to check in your lock file
|
||||
pubspec.lock
|
||||
|
||||
# Conventional directory for build outputs
|
||||
build/
|
||||
|
||||
# Directory created by dartdoc
|
||||
doc/api/
|
||||
|
||||
.DS_Store
|
||||
@@ -1,3 +0,0 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version, created by Stagehand
|
||||
@@ -1,7 +0,0 @@
|
||||
# l10n
|
||||
|
||||
A command-line application that converts .arb files to .xml files for
|
||||
translation consumption.
|
||||
|
||||
Created from templates made available by Stagehand under a BSD-style
|
||||
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE).
|
||||
@@ -1,39 +0,0 @@
|
||||
# Defines a default set of lint rules enforced for
|
||||
# projects at Google. For details and rationale,
|
||||
# see https://github.com/dart-lang/pedantic#enabled-lints.
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
|
||||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
|
||||
# Uncomment to specify additional rules.
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
|
||||
analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- avoid_types_on_closure_parameters
|
||||
- avoid_void_async
|
||||
- await_only_futures
|
||||
- camel_case_types
|
||||
- cancel_subscriptions
|
||||
- close_sinks
|
||||
- constant_identifier_names
|
||||
- control_flow_in_finally
|
||||
- empty_statements
|
||||
- hash_and_equals
|
||||
- implementation_imports
|
||||
- non_constant_identifier_names
|
||||
- package_api_docs
|
||||
- package_names
|
||||
- package_prefixed_library_names
|
||||
- test_types_in_equals
|
||||
- throw_in_finally
|
||||
- unnecessary_brace_in_string_interps
|
||||
- unnecessary_getters_setters
|
||||
- unnecessary_new
|
||||
- unnecessary_statements
|
||||
- directives_ordering
|
||||
@@ -1,9 +0,0 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:l10n_cli/l10n_cli.dart' as l10n_cli;
|
||||
|
||||
main(List<String> arguments) async {
|
||||
await l10n_cli.englishArbsToXmls();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
name: l10n_cli
|
||||
description: A sample command-line application.
|
||||
# version: 1.0.0
|
||||
# author: Rami Abou Ghanem <raboughanem@google.com>
|
||||
|
||||
environment:
|
||||
sdk: '>=2.2.0 <3.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: 1.8.0
|
||||
test: ^1.0.0
|
||||
@@ -59,10 +59,14 @@ do
|
||||
done
|
||||
|
||||
# Test that the code segment widgets that get displayed in the Flutter Material
|
||||
# gallery have been generated using the latest gallery code.
|
||||
echo "Run code segments check for 'gallery/gallery'."
|
||||
# gallery have been generated using the latest gallery code. Also test that
|
||||
# the localization scripts have been run, so that they are up to date for the
|
||||
# gallery.
|
||||
pushd gallery/gallery
|
||||
echo "Run code segments check for 'gallery/gallery'."
|
||||
"${LOCAL_SDK_PATH}/bin/flutter" pub run grinder verify-code-segments
|
||||
echo "Run localization check for 'gallery/gallery'."
|
||||
"${LOCAL_SDK_PATH}/bin/flutter" pub run grinder verify-l10n
|
||||
popd
|
||||
|
||||
echo "-- Success --"
|
||||
|
||||
Reference in New Issue
Block a user