Unverified Commit e8d29075 authored by Per Classon's avatar Per Classon Committed by GitHub

[gen_l10n] Handle single, double quotes, and dollar signs in strings (#54185)

parent 08fe78ff
...@@ -123,7 +123,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) { ...@@ -123,7 +123,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) {
final RegExp expRE = RegExp('($pluralKey)\\s*{([^}]+)}'); final RegExp expRE = RegExp('($pluralKey)\\s*{([^}]+)}');
final RegExpMatch match = expRE.firstMatch(easyMessage); final RegExpMatch match = expRE.firstMatch(easyMessage);
if (match != null && match.groupCount == 2) { if (match != null && match.groupCount == 2) {
String argValue = 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) { if (placeholder != countPlaceholder && placeholder.requiresFormatting) {
argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}String}'); argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}String}');
...@@ -131,7 +131,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) { ...@@ -131,7 +131,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) {
argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}}'); argValue = argValue.replaceAll('#${placeholder.name}#', '\${${placeholder.name}}');
} }
} }
pluralLogicArgs.add(" ${pluralIds[pluralKey]}: '$argValue'"); pluralLogicArgs.add(' ${pluralIds[pluralKey]}: $argValue');
} }
} }
...@@ -155,7 +155,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) { ...@@ -155,7 +155,7 @@ String generatePluralMethod(Message message, AppResourceBundle bundle) {
String generateMethod(Message message, AppResourceBundle bundle) { String generateMethod(Message message, AppResourceBundle bundle) {
String generateMessage() { String generateMessage() {
String messageValue = bundle.translationFor(message); String messageValue = generateString(bundle.translationFor(message));
for (final Placeholder placeholder in message.placeholders) { for (final Placeholder placeholder in message.placeholders) {
if (placeholder.requiresFormatting) { if (placeholder.requiresFormatting) {
messageValue = messageValue.replaceAll('{${placeholder.name}}', '\${${placeholder.name}String}'); messageValue = messageValue.replaceAll('{${placeholder.name}}', '\${${placeholder.name}String}');
...@@ -164,7 +164,7 @@ String generateMethod(Message message, AppResourceBundle bundle) { ...@@ -164,7 +164,7 @@ String generateMethod(Message message, AppResourceBundle bundle) {
} }
} }
return generateString(messageValue, escapeDollar: false); return messageValue;
} }
if (message.isPlural) { if (message.isPlural) {
......
...@@ -124,8 +124,12 @@ void main() { ...@@ -124,8 +124,12 @@ void main() {
'#l10n 45 (Hello World of 101 citizens)\n' '#l10n 45 (Hello World of 101 citizens)\n'
'#l10n 46 (Hello two worlds with 102 total citizens)\n' '#l10n 46 (Hello two worlds with 102 total citizens)\n'
'#l10n 47 ([Hello] -World- #123#)\n' '#l10n 47 ([Hello] -World- #123#)\n'
'#l10n 48 (Flutter\'s amazing!)\n' '#l10n 48 (\$!)\n'
'#l10n 49 (Flutter is "amazing"!)\n' '#l10n 49 (One \$)\n'
'#l10n 50 (Flutter\'s amazing!)\n'
'#l10n 51 (Flutter\'s amazing, times 2!)\n'
'#l10n 52 (Flutter is "amazing"!)\n'
'#l10n 53 (Flutter is "amazing", times 2!)\n'
'#l10n END\n' '#l10n END\n'
); );
}); });
......
...@@ -184,8 +184,12 @@ class Home extends StatelessWidget { ...@@ -184,8 +184,12 @@ class Home extends StatelessWidget {
'${localizations.helloWorldPopulation(1, 101)}', '${localizations.helloWorldPopulation(1, 101)}',
'${localizations.helloWorldPopulation(2, 102)}', '${localizations.helloWorldPopulation(2, 102)}',
'${localizations.helloWorldsInterpolation(123, "Hello", "World")}', '${localizations.helloWorldsInterpolation(123, "Hello", "World")}',
'${localizations.dollarSign}',
'${localizations.dollarSignPlural(1)}',
'${localizations.singleQuote}', '${localizations.singleQuote}',
'${localizations.singleQuotePlural(2)}',
'${localizations.doubleQuote}', '${localizations.doubleQuote}',
'${localizations.doubleQuotePlural(2)}',
]); ]);
}, },
), ),
...@@ -379,14 +383,43 @@ void main() { ...@@ -379,14 +383,43 @@ void main() {
} }
}, },
"dollarSign": "$!",
"@dollarSign": {
"description": "A message with a dollar sign."
},
"dollarSignPlural": "{count,plural, =1{One $} other{Many $}}",
"@dollarSignPlural": {
"description": "A plural message with a dollar sign.",
"placeholders": {
"count": {}
}
},
"singleQuote": "Flutter's amazing!", "singleQuote": "Flutter's amazing!",
"@singleQuote": { "@singleQuote": {
"description": "A message with a single quote." "description": "A message with a single quote."
}, },
"singleQuotePlural": "{count,plural, =1{Flutter's amazing, times 1!} other{Flutter's amazing, times {count}!}}",
"@singleQuotePlural": {
"description": "A plural message with a single quote.",
"placeholders": {
"count": {}
}
},
"doubleQuote": "Flutter is \"amazing\"!", "doubleQuote": "Flutter is \"amazing\"!",
"@doubleQuote": { "@doubleQuote": {
"description": "A message with double quotes." "description": "A message with double quotes."
},
"doubleQuotePlural": "{count,plural, =1{Flutter is \"amazing\", times 1!} other{Flutter is \"amazing\", times {count}!}}",
"@doubleQuotePlural": {
"description": "A plural message with double quotes.",
"placeholders": {
"count": {}
}
} }
} }
'''; ''';
...@@ -426,8 +459,12 @@ void main() { ...@@ -426,8 +459,12 @@ void main() {
"helloWorldPopulation": "{count,plural, =1{Hello World of {population} citizens} =2{Hello two worlds with {population} total citizens} many{Hello all {count} worlds, with a total of {population} citizens} other{Hello other {count} worlds, with a total of {population} citizens}}", "helloWorldPopulation": "{count,plural, =1{Hello World of {population} citizens} =2{Hello two worlds with {population} total citizens} many{Hello all {count} worlds, with a total of {population} citizens} other{Hello other {count} worlds, with a total of {population} citizens}}",
"helloWorldInterpolation": "[{hello}] #{world}#", "helloWorldInterpolation": "[{hello}] #{world}#",
"helloWorldsInterpolation": "{count,plural, other {[{hello}] -{world}- #{count}#}}", "helloWorldsInterpolation": "{count,plural, other {[{hello}] -{world}- #{count}#}}",
"dollarSign": "$!",
"dollarSignPlural": "{count,plural, =1{One $} other{Many $}}",
"singleQuote": "Flutter's amazing!", "singleQuote": "Flutter's amazing!",
"doubleQuote": "Flutter is \"amazing\"!" "singleQuotePlural": "{count,plural, =1{Flutter's amazing, times 1!} other{Flutter's amazing, times {count}!}",
"doubleQuote": "Flutter is \"amazing\"!",
"doubleQuotePlural": "{count,plural, =1{Flutter is \"amazing\", times 1!} other{Flutter is \"amazing\", times {count}!"
} }
'''; ''';
......
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