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

[gen_l10n] keys can contain dollar sign (#114808)

* [gen_l10n] keys can contain dollar sign

Fixes #112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart
Co-authored-by: 's avatarChristopher Fujino <fujino@google.com>
parent 75f61903
......@@ -838,15 +838,15 @@ class LocalizationsGenerator {
if (name[0] == '_') {
return false;
}
// Dart getter and method name cannot contain non-alphanumeric symbols
if (name.contains(RegExp(r'[^a-zA-Z_\d]'))) {
// Dart identifiers can only use letters, numbers, underscores, and `$`
if (name.contains(RegExp(r'[^a-zA-Z_$\d]'))) {
return false;
}
// Dart method name must start with lower case character
// Dart getter and method name should start with lower case character
if (name[0].contains(RegExp(r'[A-Z]'))) {
return false;
}
// Dart class name cannot start with a number
// Dart getter and method name cannot start with a number
if (name[0].contains(RegExp(r'\d'))) {
return false;
}
......
......@@ -2704,6 +2704,31 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
)),
);
});
testWithoutContext('can start with and contain a dollar sign', () {
const String dollarArbFile = r'''
{
"$title$": "Stocks",
"@$title$": {
"description": "Title for the application"
}
}''';
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(dollarArbFile);
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
logger: logger,
)
..loadResources()
..writeOutputFiles();
});
});
testWithoutContext('throws when the language code is not supported', () {
......
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