Unverified Commit ee17ebe5 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Use type:int without format in gen_l10n (#83132)

parent c52e8495
......@@ -202,7 +202,7 @@ class Placeholder {
final String? format;
final List<OptionalParameter> optionalParameters;
bool get requiresFormatting => <String>['DateTime', 'double', 'int', 'num'].contains(type);
bool get requiresFormatting => <String>['DateTime', 'double', 'num'].contains(type) || (type == 'int' && format != null);
bool get isNumber => <String>['double', 'int', 'num'].contains(type);
bool get hasValidNumberFormat => _validNumberFormats.contains(format);
bool get hasNumberFormatWithParameters => _numberFormatsWithNamedParameters.contains(format);
......
......@@ -2399,4 +2399,45 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
// The original pubspec file should not be overwritten.
expect(pubspecFile.readAsStringSync(), 'abcd');
});
testWithoutContext('can use type: int without specifying a format', () {
const String arbFile = '''
{
"orderNumber": "This is order #{number}.",
"@orderNumber": {
"description": "The title for an order with a given number.",
"placeholders": {
"number": {
"type": "int"
}
}
}
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(arbFile);
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
)
..loadResources()
..writeOutputFiles(BufferLogger.test());
final String localizationsFile = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file_en.dart'),
).readAsStringSync();
expect(localizationsFile, containsIgnoringWhitespace(r'''
String orderNumber(int number) {
return 'This is order #$number.';
}
'''));
expect(localizationsFile, isNot(contains(intlImportDartCode)));
});
}
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