Unverified Commit bf132dae authored by Ahmed Ashour's avatar Ahmed Ashour Committed by GitHub

[gen_l10n] correct variable name when the placeholder requiresFormatting (#86842)

parent def18c71
...@@ -202,21 +202,16 @@ String _generatePluralMethod(Message message, String translationForMessage) { ...@@ -202,21 +202,16 @@ String _generatePluralMethod(Message message, String translationForMessage) {
if (match != null && match.groupCount == 2) { if (match != null && match.groupCount == 2) {
String argValue = generateString(match.group(2)!); String argValue = generateString(match.group(2)!);
for (final Placeholder placeholder in message.placeholders) { for (final Placeholder placeholder in message.placeholders) {
if (placeholder != countPlaceholder && placeholder.requiresFormatting) { String variable = placeholder.name;
argValue = argValue.replaceAll( if (placeholder.requiresFormatting) {
'#${placeholder.name}#', variable += 'String';
_needsCurlyBracketStringInterpolation(argValue, placeholder.name)
? '\${${placeholder.name}String}'
: '\$${placeholder.name}String'
);
} else {
argValue = argValue.replaceAll(
'#${placeholder.name}#',
_needsCurlyBracketStringInterpolation(argValue, placeholder.name)
? '\${${placeholder.name}}'
: '\$${placeholder.name}'
);
} }
argValue = argValue.replaceAll(
'#${placeholder.name}#',
_needsCurlyBracketStringInterpolation(argValue, placeholder.name)
? '\${$variable}'
: '\$$variable'
);
} }
pluralLogicArgs.add(' ${pluralIds[pluralKey]}: $argValue'); pluralLogicArgs.add(' ${pluralIds[pluralKey]}: $argValue');
} }
...@@ -368,21 +363,16 @@ String _generateMethod(Message message, String translationForMessage) { ...@@ -368,21 +363,16 @@ String _generateMethod(Message message, String translationForMessage) {
String generateMessage() { String generateMessage() {
String messageValue = generateString(translationForMessage); String messageValue = generateString(translationForMessage);
for (final Placeholder placeholder in message.placeholders) { for (final Placeholder placeholder in message.placeholders) {
String variable = placeholder.name;
if (placeholder.requiresFormatting) { if (placeholder.requiresFormatting) {
messageValue = messageValue.replaceAll( variable += 'String';
'{${placeholder.name}}',
_needsCurlyBracketStringInterpolation(messageValue, placeholder.name)
? '\${${placeholder.name}String}'
: '\$${placeholder.name}String'
);
} else {
messageValue = messageValue.replaceAll(
'{${placeholder.name}}',
_needsCurlyBracketStringInterpolation(messageValue, placeholder.name)
? '\${${placeholder.name}}'
: '\$${placeholder.name}'
);
} }
messageValue = messageValue.replaceAll(
'{${placeholder.name}}',
_needsCurlyBracketStringInterpolation(messageValue, placeholder.name)
? '\${$variable}'
: '\$$variable'
);
} }
return messageValue; return messageValue;
......
...@@ -2166,6 +2166,16 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e ...@@ -2166,6 +2166,16 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
"placeholders": { "placeholders": {
"count": {} "count": {}
} }
},
"third": "{total,plural, =0{test {total}} other{ {total}}",
"@third": {
"description": "Third set of plural messages to test, for number.",
"placeholders": {
"total": {
"type": "int",
"format": "compactLong"
}
}
} }
} }
'''; ''';
...@@ -2206,6 +2216,9 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e ...@@ -2206,6 +2216,9 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
expect(localizationsFile, contains(r'${count}m')); expect(localizationsFile, contains(r'${count}m'));
expect(localizationsFile, contains(r'test $count')); expect(localizationsFile, contains(r'test $count'));
expect(localizationsFile, contains(r' $count')); expect(localizationsFile, contains(r' $count'));
expect(localizationsFile, contains(r'String totalString = totalNumberFormat'));
expect(localizationsFile, contains(r'test $totalString'));
expect(localizationsFile, contains(r' $totalString'));
}); });
testWithoutContext( testWithoutContext(
...@@ -2493,7 +2506,6 @@ String orderNumber(int number) { ...@@ -2493,7 +2506,6 @@ String orderNumber(int number) {
final String localizationsFile = fs.file( final String localizationsFile = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart'), fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart'),
).readAsStringSync(); ).readAsStringSync();
print(localizationsFile);
expect(localizationsFile, containsIgnoringWhitespace(r''' expect(localizationsFile, containsIgnoringWhitespace(r'''
AppLocalizations lookupAppLocalizations(Locale locale) { AppLocalizations lookupAppLocalizations(Locale locale) {
''')); '''));
......
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