8000 [CP-beta]feat: Arbitrary format options for localizations generation … · flutter/flutter@453dd71 · GitHub
[go: up one dir, main page]

Skip to content

Commit 453dd71

Browse files
[CP-beta]feat: Arbitrary format options for localizations generation (#102983) (#168035)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? < Replace with issue link here > ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples < Replace with changelog description here > ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) < Replace with impact description here > ### Workaround: Is there a workaround for this issue? < Replace with workaround here > ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: What are the steps to validate that this fix works? < Replace with validation steps here >
1 parent 6423adf commit 453dd71

File tree

3 files changed

+86
-12
lines changed

3 files changed

+86
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class LocalizationOptions {
356356
syntheticPackage = syntheticPackage ?? !featureFlags.isExplicitPackageDependenciesEnabled,
357357
requiredResourceAttributes = requiredResourceAttributes ?? false,
358358
nullableGetter = nullableGetter ?? true,
359-
format = format ?? false,
359+
format = format ?? true,
360360
useEscaping = useEscaping ?? false,
361361
suppressWarnings = suppressWarnings ?? false,
362362
relaxSyntax = relaxSyntax ?? false,

packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ flutter:
202202
fileSystem: fileSystem,
203203
logger: logger,
204204
artifacts: artifacts,
205-
processManager: processManager,
205+
processManager: FakeProcessManager.any(),
206206
);
207207
await createTestCommandRunner(command).run(<String>['gen-l10n']);
208208

@@ -241,7 +241,7 @@ flutter:
241241
fileSystem: fileSystem,
242242
logger: logger,
243243
artifacts: artifacts,
244-
processManager: processManager,
244+
processManager: FakeProcessManager.any(),
245245
);
246246
await createTestCommandRunner(command).run(<String>['gen-l10n']);
247247
expect(command.usage, contains(' If this value is set to false, then '));
@@ -299,6 +299,43 @@ flutter:
299299
},
300300
);
301301

302+
testUsingContext(
303+
'dart format is not run when --no-format is passed',
304+
() async {
305+
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
306+
..createSync(recursive: true);
307+
arbFile.writeAsStringSync('''
308+
{
309+
"helloWorld": "Hello, World!",
310+
"@helloWorld": {
311+
"description": "Sample description"
312+
}
313+
}''');
314+
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
315+
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
316+
317+
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
318+
fileSystem: fileSystem,
319+
logger: logger,
320+
artifacts: artifacts,
321+
processManager: processManager,
322+
);
323+
324+
await createTestCommandRunner(command).run(<String>['gen-l10n', '--no-format']);
325+
326+
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
327+
expect(outputDirectory.existsSync(), true);
328+
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
329+
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
330+
expect(processManager, hasNoRemainingExpectations);
331+
},
332+
overrides: <Type, Generator>{
333+
FeatureFlags: enableExplicitPackageDependencies,
334+
FileSystem: () => fileSystem,
335+
ProcessManager: () => FakeProcessManager.any(),
336+
},
337+
);
338+
302339
testUsingContext(
303340
'dart format is run when format: true is passed into l10n.yaml',
304341
() async {
@@ -348,6 +385,45 @@ format: true
348385
},
349386
);
350387

388+
testUsingContext(
389+
'dart format is not running when format: false is passed into l10n.yaml',
390+
() async {
391+
final File arbFile = fileSystem.file(fileSystem.path.join('lib', 'l10n', 'app_en.arb'))
392+
..createSync(recursive: true);
393+
arbFile.writeAsStringSync('''
394+
{
395+
"helloWorld": "Hello, World!",
396+
"@helloWorld": {
397+
"description": "Sample description"
398+
}
399+
}''');
400+
final File configFile = fileSystem.file('l10n.yaml')..createSync();
401+
configFile.writeAsStringSync('''
402+
format: false
403+
''');
404+
final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync();
405+
pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec);
406+
final GenerateLocalizationsCommand command = GenerateLocalizationsCommand(
407+
fileSystem: fileSystem,
408+
logger: logge A3D4 r,
409+
artifacts: artifacts,
410+
processManager: processManager,
411+
);
412+
await createTestCommandRunner(command).run(<String>['gen-l10n']);
413+
414+
final Directory outputDirectory = fileSystem.directory(fileSystem.path.join('lib', 'l10n'));
415+
expect(outputDirectory.existsSync(), true);
416+
expect(outputDirectory.childFile('app_localizations_en.dart').existsSync(), true);
417+
expect(outputDirectory.childFile('app_localizations.dart').existsSync(), true);
418+
expect(processManager, hasNoRemainingExpectations);
419+
},
420+
overrides: <Type, Generator>{
421+
FeatureFlags: enableExplicitPackageDependencies,
422+
FileSystem: () => fileSystem,
423+
ProcessManager: () => FakeProcessManager.any(),
424+
},
425+
);
426+
351427
// Regression test for https://github.com/flutter/flutter/issues/119594
352428
testUsingContext(
353429
'dart format is working when the untranslated messages file is produced',

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ void main() {
7676
late MemoryFileSystem fs;
7777
late BufferLogger logger;
7878
late Artifacts artifacts;
79-
late ProcessManager processManager;
8079
late String defaultL10nPathString;
8180
late String syntheticPackagePath;
8281
late String syntheticL10nPackagePath;
@@ -152,7 +151,6 @@ void main() {
152151
fs = MemoryFileSystem.test();
153152
logger = BufferLogger.test();
154153
artifacts = Artifacts.test();
155-
processManager = FakeProcessManager.empty();
156154

157155
defaultL10nPathString = fs.path.join('lib', 'l10n');
158156
syntheticPackagePath = fs.path.join('.dart_tool', 'flutter_gen');
@@ -757,7 +755,7 @@ flutter:
757755
projectDir: projectDir,
758756
dependenciesDir: fs.currentDirectory,
759757
artifacts: artifacts,
760-
processManager: processManager,
758+
processManager: FakeProcessManager.any(),
761759
);
762760
});
763761

@@ -780,7 +778,7 @@ flutter:
780778
projectDir: fs.currentDirectory,
781779
dependenciesDir: fs.currentDirectory,
782780
artifacts: artifacts,
783-
processManager: processManager,
781+
processManager: FakeProcessManager.any(),
784782
);
785783
});
786784

@@ -809,7 +807,7 @@ flutter:
809807
projectDir: fs.currentDirectory,
810808
dependenciesDir: fs.currentDirectory,
811809
artifacts: artifacts,
812-
processManager: processManager,
810+
processManager: FakeProcessManager.any(),
813811
);
814812

815813
expect(generator.inputDirectory.path, '/lib/l10n/');
@@ -880,7 +878,7 @@ flutter:
880 FC49 878
projectDir: fs.currentDirectory,
881879
dependenciesDir: fs.currentDirectory,
882880
artifacts: artifacts,
883-
processManager: processManager,
881+
processManager: FakeProcessManager.any(),
884882
),
885883
throwsToolExit(
886884
message:
@@ -916,7 +914,7 @@ flutter:\r
916914
projectDir: fs.currentDirectory,
917915
dependenciesDir: fs.currentDirectory,
918916
artifacts: artifacts,
919-
processManager: processManager,
917+
processManager: FakeProcessManager.any(),
920918
);
921919
final String content = getInPackageGeneratedFileContent(locale: 'en');
922920
expect(content, contains('\r\n'));
@@ -940,7 +938,7 @@ flutter:\r
940938
projectDir: fs.currentDirectory,
941939
dependenciesDir: fs.currentDirectory,
942940
artifacts: artifacts,
943-
processManager: processManager,
941+
processManager: FakeProcessManager.any(),
944942
);
945943

946944
expect(fs.file('/lib/l10n/app_localizations_en.dart').readAsStringSync(), '''
@@ -973,7 +971,7 @@ class AppLocalizationsEn extends AppLocalizations {
973971
projectDir: fs.currentDirectory,
974972
dependenciesDir: fs.currentDirectory,
975973
artifacts: artifacts,
976-
processManager: processManager,
974+
processManager: FakeProcessManager.any(),
977975
);
978976

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

0 commit comments

Comments
 (0)
0