forked from firka/flutter
[Gen-l10n] Add Message.resourceId and locale to all L10nException error messages (#163654)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> I've had this problem today https://github.com/flutter/flutter/issues/163627 where the generator would display me this error message: > Error: The placeholder, count, has its "type" resource attribute set to the "null" type in locale "en", but it is "num" in the template placeholder. For compatibility with template placeholder, change the "type" attribute to "num". Unfortunately this isn't really actionable as it omits to which message it's actually referring to! So I added the id of the message to all error message and the locale of the message to all messages that hadn't had it already. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
@@ -134,8 +134,8 @@ List<String> generateMethodParameters(
|
||||
final Placeholder? localePlaceholder = localePlaceholders?[e.key];
|
||||
if (localePlaceholder != null && placeholder.type != localePlaceholder.type) {
|
||||
throw L10nException(
|
||||
'The placeholder, ${placeholder.name}, has its "type" resource attribute set to '
|
||||
'the "${localePlaceholder.type}" type in locale "$locale", but it is "${placeholder.type}" '
|
||||
'For the message "${message.resourceId}" the placeholder "${placeholder.name}" has its "type" resource attribute set to '
|
||||
'the type "${localePlaceholder.type}" in locale "$locale", but it is "${placeholder.type}" '
|
||||
'in the template placeholder. For compatibility with template placeholder, change '
|
||||
'the "type" attribute to "${placeholder.type}".',
|
||||
);
|
||||
@@ -163,8 +163,8 @@ String generateDateFormattingLogic(Message message, LocaleInfo locale) {
|
||||
final String? placeholderFormat = placeholder.format;
|
||||
if (placeholderFormat == null) {
|
||||
throw L10nException(
|
||||
'The placeholder, ${placeholder.name}, has its "type" resource attribute set to '
|
||||
'the "${placeholder.type}" type. To properly resolve for the right '
|
||||
'For the message "${message.resourceId}" the placeholder "${placeholder.name}" has its "type" resource attribute set to '
|
||||
'the type "${placeholder.type}" in locale "$locale". To properly resolve for the right '
|
||||
'${placeholder.type} format, the "format" attribute needs to be set '
|
||||
'to determine which DateFormat to use. \n'
|
||||
"Check the intl library's DateFormat class constructors for allowed "
|
||||
@@ -176,8 +176,8 @@ String generateDateFormattingLogic(Message message, LocaleInfo locale) {
|
||||
(isCustomDateFormat == null || !isCustomDateFormat)) {
|
||||
if (placeholder.dateFormatParts.length > 1) {
|
||||
throw L10nException(
|
||||
'Date format "$placeholderFormat" for placeholder '
|
||||
'${placeholder.name} contains at least one invalid date format. '
|
||||
'For the message "${message.resourceId}" the date format "$placeholderFormat" for placeholder '
|
||||
'${placeholder.name} contains at least one invalid date format in locale "$locale". '
|
||||
'Ensure all date formats joined by a "+" character have '
|
||||
'a corresponding DateFormat constructor.\n Check the intl '
|
||||
"library's DateFormat class constructors for allowed date formats.",
|
||||
@@ -185,9 +185,9 @@ String generateDateFormattingLogic(Message message, LocaleInfo locale) {
|
||||
}
|
||||
|
||||
throw L10nException(
|
||||
'Date format "$placeholderFormat" for placeholder '
|
||||
'For the message "${message.resourceId}" the date format "$placeholderFormat" for placeholder '
|
||||
'${placeholder.name} does not have a corresponding DateFormat '
|
||||
"constructor\n. Check the intl library's DateFormat class "
|
||||
'constructor in locale "$locale". Check the intl library\'s DateFormat class '
|
||||
'constructors for allowed date formats, or set "isCustomDateFormat" attribute '
|
||||
'to "true".',
|
||||
);
|
||||
@@ -228,8 +228,8 @@ String generateNumberFormattingLogic(Message message, LocaleInfo locale) {
|
||||
final String? placeholderFormat = placeholder.format;
|
||||
if (!placeholder.hasValidNumberFormat || placeholderFormat == null) {
|
||||
throw L10nException(
|
||||
'Number format $placeholderFormat for the ${placeholder.name} '
|
||||
'placeholder does not have a corresponding NumberFormat constructor.\n'
|
||||
'For the message "${message.resourceId}" the number format $placeholderFormat for the ${placeholder.name} '
|
||||
'placeholder does not have a corresponding NumberFormat constructor in locale "$locale".\n'
|
||||
"Check the intl library's NumberFormat class constructors for allowed "
|
||||
'number formats.',
|
||||
);
|
||||
@@ -1406,9 +1406,9 @@ The plural cases must be one of "=0", "=1", "=2", "zero", "one", "two", "few", "
|
||||
// Check that formatType is a valid intl.DateFormat.
|
||||
if (!validDateFormats.contains(formatType.value)) {
|
||||
throw L10nParserException(
|
||||
'Date format "${formatType.value!}" for placeholder '
|
||||
'For message "${message.resourceId}" the date format "${formatType.value!}" for placeholder '
|
||||
'$identifierName does not have a corresponding DateFormat '
|
||||
"constructor\n. Check the intl library's DateFormat class "
|
||||
'constructor in locale "$locale"\n. Check the intl library\'s DateFormat class '
|
||||
'constructors for allowed date formats, or set "isCustomDateFormat" attribute '
|
||||
'to "true".',
|
||||
_inputFileNames[locale]!,
|
||||
|
||||
@@ -505,7 +505,7 @@ class Message {
|
||||
}
|
||||
if (allPlaceholdersMap is! Map<String, Object?>) {
|
||||
throw L10nException(
|
||||
'The "placeholders" attribute for message $resourceId, is not '
|
||||
'The "placeholders" attribute for message "$resourceId", is not '
|
||||
'properly formatted. Ensure that it is a map with string valued keys.',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1779,6 +1779,8 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "springBegins"'),
|
||||
contains('locale "en"'),
|
||||
contains('asdf'),
|
||||
contains('springStartDate'),
|
||||
contains('does not have a corresponding DateFormat'),
|
||||
@@ -1913,9 +1915,11 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "loggedIn"'),
|
||||
contains('locale "en"'),
|
||||
contains('"foo+bar+baz"'),
|
||||
contains('lastLoginDate'),
|
||||
contains('contains at least one invalid date format.'),
|
||||
contains('contains at least one invalid date format'),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1945,9 +1949,11 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "loggedIn"'),
|
||||
contains('locale "en"'),
|
||||
contains('"yMd+Hm+"'),
|
||||
contains('lastLoginDate'),
|
||||
contains('contains at least one invalid date format.'),
|
||||
contains('contains at least one invalid date format'),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -1976,7 +1982,11 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
isA<L10nException>().having(
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
contains('the "format" attribute needs to be set'),
|
||||
allOf(
|
||||
contains('message "springBegins"'),
|
||||
contains('locale "en"'),
|
||||
contains('the "format" attribute needs to be set'),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -2163,8 +2173,12 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
isA<L10nException>().having(
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
contains(
|
||||
'The placeholder, springStartDate, has its "type" resource attribute set to the "String" type in locale "ja", but it is "DateTime" in the template placeholder.',
|
||||
allOf(
|
||||
contains('placeholder "springStartDate"'),
|
||||
contains('locale "ja"'),
|
||||
contains(
|
||||
'"type" resource attribute set to the type "String" in locale "ja", but it is "DateTime" in the template placeholder.',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -2210,8 +2224,12 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
isA<L10nException>().having(
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
contains(
|
||||
'The placeholder, springStartDate, has its "type" resource attribute set to the "Object" type in locale "ja", but it is "DateTime" in the template placeholder.',
|
||||
allOf(
|
||||
contains('placeholder "springStartDate"'),
|
||||
contains('locale "ja"'),
|
||||
contains(
|
||||
'has its "type" resource attribute set to the type "Object" in locale "ja", but it is "DateTime" in the template placeholder.',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -2366,6 +2384,8 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "courseCompletion"'),
|
||||
contains('locale "en"'),
|
||||
contains('asdf'),
|
||||
contains('progress'),
|
||||
contains('does not have a corresponding NumberFormat'),
|
||||
@@ -2469,6 +2489,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "helloWorlds"'),
|
||||
contains('is not properly formatted'),
|
||||
contains('Ensure that it is a map with string valued keys'),
|
||||
),
|
||||
@@ -2519,6 +2540,7 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
(L10nException e) => e.message,
|
||||
'message',
|
||||
allOf(
|
||||
contains('message "genderSelect"'),
|
||||
contains('is not properly formatted'),
|
||||
contains('Ensure that it is a map with string valued keys'),
|
||||
),
|
||||
@@ -2632,8 +2654,12 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
} on L10nException {
|
||||
expect(
|
||||
logger.errorText,
|
||||
contains(
|
||||
'Date format "yMMMMMd" for placeholder today does not have a corresponding DateFormat constructor',
|
||||
allOf(
|
||||
contains('message "datetime"'),
|
||||
contains('locale "en"'),
|
||||
contains(
|
||||
'date format "yMMMMMd" for placeholder today does not have a corresponding DateFormat constructor',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user