internationalization: fix select with incorrect message (#90096)

This commit is contained in:
Ahmed Ashour 2021-09-16 18:23:22 +02:00 committed by GitHub
parent cd1892f04f
commit eb185d73ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 0 deletions

View file

@ -300,6 +300,11 @@ String _generateSelectMethod(Message message, String translationForMessage) {
);
}
}
} else {
throw L10nException(
'Incorrect select message format for: ${message.resourceId}.\n'
'Check to see if the select message is in the proper ICU syntax format.'
);
}
final List<String> parameters = message.placeholders.map((Placeholder placeholder) {

View file

@ -1909,6 +1909,46 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
)),
);
});
testWithoutContext('should throw attempting to generate a select message with an incorrect message', () {
const String selectMessageWithoutPlaceholdersAttribute = '''
{
"genderSelect": "{gender, select,}",
"@genderSelect": {
"placeholders": {
"gender": {}
}
}
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(selectMessageWithoutPlaceholdersAttribute);
expect(
() {
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
)
..loadResources()
..writeOutputFiles(BufferLogger.test());
},
throwsA(isA<L10nException>().having(
(L10nException e) => e.message,
'message',
allOf(
contains('Incorrect select message format for'),
contains('Check to see if the select message is in the proper ICU syntax format.'),
),
)),
);
});
});
testWithoutContext('intl package import should be omitted in subclass files when no plurals are included', () {