Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[CP-beta]feat: Arbitrary format options for localizations generation (#102983) #168035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class LocalizationOptions {
syntheticPackage = syntheticPackage ?? !featureFlags.isExplicitPackageDependenciesEnabled,
requiredResourceAttributes = requiredResourceAttributes ?? false,
nullableGetter = nullableGetter ?? true,
format = format ?? false,
format = format ?? true,
useEscaping = useEscaping ?? false,
suppressWarnings = suppressWarnings ?? false,
relaxSyntax = relaxSyntax ?? false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ flutter:
fileSystem: fileSystem,
logger: logger,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);

Expand Down Expand Up @@ -241,7 +241,7 @@ flutter:
fileSystem: fileSystem,
logger: logger,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);
expect(command.usage, contains(' If this value is set to false, then '));
Expand Down Expand Up @@ -299,6 +299,43 @@ flutter:
},
);

testUsingContext(
'dart format is not run when --no-format is passed',
() async {
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
..createSync(recursive: true);
arbFile.writeAsStringSync('''
{
"helloWorld": "Hello, World!",
"@helloWorld": {
"description": "Sample description"
}
}''');
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);

final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
fileSystem: fileSystem,
logger: logger,
artifacts: artifacts,
processManager: processManager,
);

await createTestCommandRunner(command).run(<String>['gen-l10n', '--no-format']);

final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
expect(processManager, hasNoRemainingExpectations);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
);

testUsingContext(
'dart format is run when format: true is passed into l10n.yaml',
() async {
Expand Down Expand Up @@ -348,6 +385,45 @@ format: true
},
);

testUsingContext(
'dart format is not running when format: false is passed into l10n.yaml',
() async {
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
..createSync(recursive: true);
arbFile.writeAsStringSync('''
{
"helloWorld": "Hello, World!",
"@helloWorld": {
"description": "Sample description"
}
}''');
final File configFile = fileSystem.file('l10n.yaml')..createSync();
configFile.writeAsStringSync('''
format: false
''');
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
fileSystem: fileSystem,
logger: logger,
artifacts: artifacts,
processManager: processManager,
);
await createTestCommandRunner(command).run(<String>['gen-l10n']);

final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
expect(outputDirectory.existsSync(), true);
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
expect(processManager, hasNoRemainingExpectations);
},
overrides: <Type, Generator>{
FeatureFlags: enableExplicitPackageDependencies,
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
},
);

// Regression test for https://github.com/flutter/flutter/issues/119594
testUsingContext(
'dart format is working when the untranslated messages file is produced',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void main() {
late MemoryFileSystem fs;
late BufferLogger logger;
late Artifacts artifacts;
late ProcessManager processManager;
late String defaultL10nPathString;
late String syntheticPackagePath;
late String syntheticL10nPackagePath;
Expand Down Expand Up @@ -152,7 +151,6 @@ void main() {
fs = MemoryFileSystem.test();
logger = BufferLogger.test();
artifacts = Artifacts.test();
processManager = FakeProcessManager.empty();

defaultL10nPathString = fs.path.join('lib', 'l10n');
syntheticPackagePath = fs.path.join('.dart_tool', 'flutter_gen');
Expand Down Expand Up @@ -757,7 +755,7 @@ flutter:
projectDir: projectDir,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);
});

Expand All @@ -780,7 +778,7 @@ flutter:
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);
});

Expand Down Expand Up @@ -809,7 +807,7 @@ flutter:
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);

expect(generator.inputDirectory.path, '/lib/l10n/');
Expand Down Expand Up @@ -880,7 +878,7 @@ flutter:
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
),
throwsToolExit(
message:
Expand Down Expand Up @@ -916,7 +914,7 @@ flutter:\r
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);
final String content = getInPackageGeneratedFileContent(locale: 'en');
expect(content, contains('\r\n'));
Expand All @@ -940,7 +938,7 @@ flutter:\r
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);

expect(fs.file('/lib/l10n/app_localizations_en.dart').readAsStringSync(), '''
Expand Down Expand Up @@ -973,7 +971,7 @@ class AppLocalizationsEn extends AppLocalizations {
projectDir: fs.currentDirectory,
dependenciesDir: fs.currentDirectory,
artifacts: artifacts,
processManager: processManager,
processManager: FakeProcessManager.any(),
);

expect(fs.file('/lib/l10n/app_localizations_en.dart').readAsStringSync(), '''
Expand Down