Use type:int without format in gen_l10n (#83132)
This commit is contained in:
committed by
GitHub
parent
c52e8495f3
commit
ee17ebe51f
@@ -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)));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user