[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: Christopher Fujino <fujino@google.com>
This commit is contained in:
Ahmed Ashour 2022-12-01 22:42:02 +01:00 committed by GitHub
parent 75f61903e0
commit f6224f368a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View file

@ -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;
}

View file

@ -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', () {