Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 646088931
  • Loading branch information
Googler authored and Copybara-Service committed Jun 24, 2024
1 parent e73fca2 commit 404c2cc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkgs/intl_translation/lib/src/messages/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ abstract class Message {

var classPlusMethod = Message.classPlusMethodName(node, outerName);
var classMatch = classPlusMethod != null && (givenName == classPlusMethod);
if (!(hasOuterName && (simpleMatch || classMatch))) {
var mapOrListLiteralWithoutParameters =
(node.parent is ListLiteral || node.parent is MapLiteralEntry) &&
!hasParameters;
if (!(hasOuterName &&
(simpleMatch || classMatch || mapOrListLiteralWithoutParameters))) {
throw MessageExtractionException(
"The 'name' argument for Intl.message must match either "
'the name of the containing function or <ClassName>_<methodName> ('
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Map<String, String> french = {
'thisNameIsAVariable': 'Ce message devrait ignorer la traduction',
'noExamples': 'Ce message devrait ignorer la traduction',
'badExamples': 'Ce message devrait ignorer la traduction',
'listElement': 'Ceci est un élément de liste nommé',
'mapElement': 'Ceci est un élément de carte nommé',
};

// Used to test having translations in multiple files.
Expand Down Expand Up @@ -164,6 +166,8 @@ Map<String, String> german = {
'thisNameIsAVariable': 'Diese Nachricht sollte die Übersetzung überspringen',
'noExamples': 'Diese Nachricht sollte die Übersetzung überspringen',
'badExamples': 'Diese Nachricht sollte die Übersetzung überspringen',
'listElement': 'Dies ist ein benanntes Listenelement',
'mapElement': 'Dies ist ein benanntes Kartenelement',
};

/// The output directory for translated files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ String badExamples(String x) =>
args: [x],
examples: {'x': 3});

List<String> messageList() => <String>[
Intl.message('This is a named list element',
name: 'listElement', desc: 'List element'),
];

Map<String, String> messageMap() => <String, String>{
'arbitraryKey': Intl.message('This is a named map element',
name: 'mapElement', desc: 'Map element')
};

void printStuff(Intl locale) {
// Use a name that's not a literal so this will get skipped. Then we have
// a name that's not in the original but we include it in the French
Expand Down Expand Up @@ -342,6 +352,8 @@ void printStuff(Intl locale) {
printOut(wrongName('a'));
printOut(badDescription('a'));
printOut(badExamples('a'));
printOut(messageList()[0]);
printOut(messageMap()['arbitraryKey']!);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ void verifyResult() {
verify('Wrong name for message: a');
verify('Description must be a string literal: a');
verify('Examples must be const literal map: a');
verify('This is a named list element');
verify('This is a named map element');
verify('-------------------------------------------');

// French translations.
Expand Down Expand Up @@ -169,6 +171,8 @@ void verifyResult() {
verify('Wrong name for message: a');
verify('Description must be a string literal: a');
verify('Examples must be const literal map: a');
verify('Ceci est un élément de liste nommé');
verify('Ceci est un élément de carte nommé');
verify('-------------------------------------------');

// German translations.
Expand Down Expand Up @@ -247,6 +251,8 @@ void verifyResult() {
verify('Wrong name for message: a');
verify('Description must be a string literal: a');
verify('Examples must be const literal map: a');
verify('Dies ist ein benanntes Listenelement');
verify('Dies ist ein benanntes Kartenelement');

if (lineIterator.moveNext()) {
throw 'more messages than expected';
Expand Down

0 comments on commit 404c2cc

Please sign in to comment.