Use num on plural (#93228)
This commit is contained in:
@@ -87,7 +87,7 @@ List<String> generateMethodParameters(Message message) {
|
||||
assert(message.placeholders.isNotEmpty);
|
||||
final Placeholder? countPlaceholder = message.isPlural ? message.getCountPlaceholder() : null;
|
||||
return message.placeholders.map((Placeholder placeholder) {
|
||||
final String? type = placeholder == countPlaceholder ? 'int' : placeholder.type;
|
||||
final String? type = placeholder == countPlaceholder ? 'num' : placeholder.type;
|
||||
return '$type ${placeholder.name}';
|
||||
}).toList();
|
||||
}
|
||||
@@ -226,7 +226,7 @@ String _generatePluralMethod(Message message, String translationForMessage) {
|
||||
}
|
||||
|
||||
final List<String> parameters = message.placeholders.map((Placeholder placeholder) {
|
||||
final String? placeholderType = placeholder == countPlaceholder ? 'int' : placeholder.type;
|
||||
final String? placeholderType = placeholder == countPlaceholder ? 'num' : placeholder.type;
|
||||
return '$placeholderType ${placeholder.name}';
|
||||
}).toList();
|
||||
|
||||
|
||||
@@ -2708,4 +2708,47 @@ String orderNumber(int number) {
|
||||
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||
'''));
|
||||
});
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/pull/93228
|
||||
testWithoutContext('should use num type for plural', () {
|
||||
const String arbFile = '''
|
||||
{
|
||||
"tryToPollute": "{count, plural, =0{零} =1{一} other{其他}}",
|
||||
"@tryToPollute": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"withoutType": "{count, plural, =0{零} =1{一} other{其他}}",
|
||||
"@withoutType": {
|
||||
"placeholders": {
|
||||
"count": {}
|
||||
}
|
||||
}
|
||||
}''';
|
||||
|
||||
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 tryToPollute(num count) {'));
|
||||
expect(localizationsFile, containsIgnoringWhitespace(r'String withoutType(num count) {'));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user