From eb185d73ce5d6bd8ef60cce9d8848cac3e4090a8 Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Thu, 16 Sep 2021 18:23:22 +0200 Subject: [PATCH] internationalization: fix select with incorrect message (#90096) --- .../lib/src/localizations/gen_l10n.dart | 5 +++ .../generate_localizations_test.dart | 40 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index afc6519460e..a45d69beed0 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -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 parameters = message.placeholders.map((Placeholder placeholder) { diff --git a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart index 9e4e1a88eaf..69399069b9e 100644 --- a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart @@ -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().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', () {