Integration test for the gen_l10n tool (#49586)

This commit is contained in:
Hans Muller
2020-01-29 12:45:03 -08:00
committed by GitHub
parent dbaa4c2374
commit 3f2c6ea724
6 changed files with 393 additions and 34 deletions

View File

@@ -63,6 +63,9 @@ Future<void> main(List<String> arguments) async {
exit(0);
}
final String flutterRoot = Platform.environment['FLUTTER_ROOT'];
final String flutterBin = Platform.isWindows ? 'flutter.bat' : 'flutter';
final String flutterPath = flutterRoot == null ? flutterBin : path.join(flutterRoot, 'bin', flutterBin);
final String arbPathString = results['arb-dir'] as String;
final String outputFileString = results['output-localization-file'] as String;
final String templateArbFileName = results['template-arb-file'] as String;
@@ -91,13 +94,13 @@ Future<void> main(List<String> arguments) async {
exitWithError(e.message);
}
final ProcessResult pubGetResult = await Process.run('flutter', <String>['pub', 'get']);
final ProcessResult pubGetResult = await Process.run(flutterPath, <String>['pub', 'get']);
if (pubGetResult.exitCode != 0) {
stderr.write(pubGetResult.stderr);
exit(1);
}
final ProcessResult generateFromArbResult = await Process.run('flutter', <String>[
final ProcessResult generateFromArbResult = await Process.run(flutterPath, <String>[
'pub',
'run',
'intl_translation:generate_from_arb',

View File

@@ -223,7 +223,7 @@ String genSimpleMethod(Message message) {
String genSimpleMethodMessage() {
String messageValue = message.value;
for (final Placeholder placeholder in message.placeholders) {
messageValue = messageValue.replaceAll('{${placeholder.name}}', '\$${placeholder.name}');
messageValue = messageValue.replaceAll('{${placeholder.name}}', '\${${placeholder.name}}');
}
final String rawMessage = generateString(messageValue); // "r'...'"
return rawMessage.substring(1);
@@ -300,9 +300,9 @@ String generatePluralMethod(Message message) {
String argValue = match.group(2);
for (final Placeholder placeholder in message.placeholders) {
if (placeholder.requiresFormatting) {
argValue = argValue.replaceAll('#${placeholder.name}#', '\$${placeholder.name}String');
argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}String}');
} else {
argValue = argValue.replaceAll('#${placeholder.name}#', '\$${placeholder.name}');
argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}}');
}
}
intlMethodArgs.add("${pluralIds[pluralKey]}: '$argValue'");

View File

@@ -113,8 +113,11 @@ import 'messages_all.dart';
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the @className.supportedLocales
/// be consistent with the languages listed in the @(className).supportedLocales
/// property.
// ignore_for_file: unnecessary_brace_in_string_interps
class @(className) {
@(className)(Locale locale) : _localeName = Intl.canonicalizedLocale(locale.toString());
@@ -129,7 +132,7 @@ class @(className) {
return Localizations.of<@(className)>(context, @(className));
}
static const LocalizationsDelegate<@(className)> delegate = _@(classNameDelegate)();
static const LocalizationsDelegate<@(className)> delegate = _@(className)Delegate();
/// A list of this localizations delegate along with the default localizations
/// delegates.