Unverified Commit e8b3fe8a authored by Shueh Chou Lu's avatar Shueh Chou Lu Committed by GitHub

Use num on plural (#93228)

parent 4aad63a6
......@@ -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) {'));
});
}
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