Unverified Commit 21f3ce8b authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

[gen_l10n] Multiline descriptions (#116380)

* init

* empty commit to start google testing
parent e2fb672a
......@@ -201,7 +201,11 @@ Map<String, String> pluralCases = <String, String>{
};
String generateBaseClassMethod(Message message, LocaleInfo? templateArbLocale) {
final String comment = message.description ?? 'No description provided for @${message.resourceId}.';
final String comment = message
.description
?.split('\n')
.map((String line) => ' /// $line')
.join('\n') ?? ' /// No description provided for @${message.resourceId}.';
final String templateLocaleTranslationComment = '''
/// In $templateArbLocale, this message translates to:
/// **'${generateString(message.value)}'**''';
......
......@@ -179,14 +179,14 @@ class @(class) extends @(baseLanguageClassName) {
''';
const String baseClassGetterTemplate = '''
/// @(comment)
@(comment)
///
@(templateLocaleTranslationComment)
String get @(name);
''';
const String baseClassMethodTemplate = '''
/// @(comment)
@(comment)
///
@(templateLocaleTranslationComment)
String @(name)(@(parameters));
......
......@@ -1318,6 +1318,76 @@ class AppLocalizationsEn extends AppLocalizations {
^'''));
}
});
testWithoutContext('no description generates generic comment', () {
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(r'''
{
"helloWorld": "Hello world!"
}''');
l10nDirectory.childFile(esArbFileName)
.writeAsStringSync(singleEsMessageArbFileString);
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
logger: logger,
)
..loadResources()
..writeOutputFiles();
final File baseLocalizationsFile = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart')
);
expect(baseLocalizationsFile.existsSync(), isTrue);
final String baseLocalizationsFileContents = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart')
).readAsStringSync();
expect(baseLocalizationsFileContents, contains('/// No description provided for @helloWorld.'));
});
testWithoutContext('multiline descriptions are correctly formatted as comments', () {
final Directory l10nDirectory = fs.currentDirectory.childDirectory('lib').childDirectory('l10n')
..createSync(recursive: true);
l10nDirectory.childFile(defaultTemplateArbFileName)
.writeAsStringSync(r'''
{
"helloWorld": "Hello world!",
"@helloWorld": {
"description": "The generic example string in every language.\nUse this for tests!"
}
}''');
l10nDirectory.childFile(esArbFileName)
.writeAsStringSync(singleEsMessageArbFileString);
LocalizationsGenerator(
fileSystem: fs,
inputPathString: defaultL10nPathString,
outputPathString: defaultL10nPathString,
templateArbFileName: defaultTemplateArbFileName,
outputFileString: defaultOutputFileString,
classNameString: defaultClassNameString,
logger: logger,
)
..loadResources()
..writeOutputFiles();
final File baseLocalizationsFile = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart')
);
expect(baseLocalizationsFile.existsSync(), isTrue);
final String baseLocalizationsFileContents = fs.file(
fs.path.join(syntheticL10nPackagePath, 'output-localization-file.dart')
).readAsStringSync();
expect(baseLocalizationsFileContents, contains('''
/// The generic example string in every language.
/// Use this for tests!'''));
});
testWithoutContext('message without placeholders - should generate code comment with description and template message translation', () {
_standardFlutterDirectoryL10nSetup(fs);
LocalizationsGenerator(
......
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