mirror of
https://github.com/flutter/flutter
synced 2024-08-28 04:21:14 +00:00
[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:
parent
75f61903e0
commit
f6224f368a
|
@ -838,15 +838,15 @@ class LocalizationsGenerator {
|
||||||
if (name[0] == '_') {
|
if (name[0] == '_') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Dart getter and method name cannot contain non-alphanumeric symbols
|
// Dart identifiers can only use letters, numbers, underscores, and `$`
|
||||||
if (name.contains(RegExp(r'[^a-zA-Z_\d]'))) {
|
if (name.contains(RegExp(r'[^a-zA-Z_$\d]'))) {
|
||||||
return false;
|
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]'))) {
|
if (name[0].contains(RegExp(r'[A-Z]'))) {
|
||||||
return false;
|
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'))) {
|
if (name[0].contains(RegExp(r'\d'))) {
|
||||||
return false;
|
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', () {
|
testWithoutContext('throws when the language code is not supported', () {
|
||||||
|
|
Loading…
Reference in a new issue