Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit f6224f3

Browse files
[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 <[email protected]>
1 parent 75f6190 commit f6224f3

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -838,15 +838,15 @@ class LocalizationsGenerator {
838838
if (name[0] == '_') {
839839
return false;
840840
}
841-
// Dart getter and method name cannot contain non-alphanumeric symbols
842-
if (name.contains(RegExp(r'[^a-zA-Z_\d]'))) {
841+
// Dart identifiers can only use letters, numbers, underscores, and `$`
842+
if (name.contains(RegExp(r'[^a-zA-Z_$\d]'))) {
843843
return false;
844844
}
845-
// Dart method name must start with lower case character
845+
// Dart getter and method name should start with lower case character
846846
if (name[0].contains(RegExp(r'[A-Z]'))) {
847847
return false;
848848
}
849-
// Dart class name cannot start with a number
849+
// Dart getter and method name cannot start with a number
850850
if (name[0].contains(RegExp(r'\d'))) {
851851
return false;
852852
}

packages/flutter_tools/test/general.shard/generate_localizations_test.dart

+25
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,31 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
27042704
)),
27052705
);
27062706
});
2707+
2708+
testWithoutContext('can start with and contain a dollar sign', () {
2709+
const String dollarArbFile = r'''
2710+
{
2711+
"$title$": "Stocks",
2712+
"@$title$": {
2713+
"description": "Title for the application"
2714+
}
2715+
}''';
2716+
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
2717+
..createSync(recursive: true);
2718+
l10nDirectory.childFile(defaultTemplateArbFileName)
2719+
.writeAsStringSync(dollarArbFile);
2720+
2721+
LocalizationsGenerator(
2722+
fileSystem: fs,
2723+
inputPathString: defaultL10nPathString,
2724+
templateArbFileName: defaultTemplateArbFileName,
2725+
outputFileString: defaultOutputFileString,
2726+
classNameString: defaultClassNameString,
2727+
logger: logger,
2728+
)
2729+
..loadResources()
2730+
..writeOutputFiles();
2731+
});
27072732
});
27082733

27092734
testWithoutContext('throws when the language code is not supported', () {

0 commit comments

Comments
 (0)