Skip to content

Commit

Permalink
[gen_l10n] keys can contain dollar sign (flutter#114808)
Browse files Browse the repository at this point in the history
* [gen_l10n] keys can contain dollar sign

Fixes flutter#112250

* Update packages/flutter_tools/lib/src/localizations/gen_l10n.dart

Co-authored-by: Christopher Fujino <fujino@google.com>
  • Loading branch information
2 people authored and mit-mit committed Dec 6, 2022
1 parent 99877dd commit a1abbbe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/localizations/gen_l10n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit a1abbbe

Please sign in to comment.