diff --git a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart index 5b5e751646..0738e0ba2f 100644 --- a/packages/flutter_tools/lib/src/build_system/targets/localizations.dart +++ b/packages/flutter_tools/lib/src/build_system/targets/localizations.dart @@ -45,9 +45,17 @@ class GenerateLocalizationsTarget extends Target { final File configFile = environment.projectDir.childFile('l10n.yaml'); assert(configFile.existsSync()); - final LocalizationOptions options = parseLocalizationsOptions( + // Keep in mind that this is also defined in the following locations: + // 1. flutter_tools/lib/src/commands/generate_localizations.dart + // 2. flutter_tools/test/general.shard/build_system/targets/localizations_test.dart + // Keep the value consistent in all three locations to ensure behavior is the + // same across "flutter gen-l10n" and "flutter run". + final String defaultArbDir = environment.fileSystem.path.join('lib', 'l10n'); + + final LocalizationOptions options = parseLocalizationsOptionsFromYAML( file: configFile, logger: environment.logger, + defaultArbDir: defaultArbDir, ); final DepfileService depfileService = DepfileService( logger: environment.logger, diff --git a/packages/flutter_tools/lib/src/commands/generate_localizations.dart b/packages/flutter_tools/lib/src/commands/generate_localizations.dart index a021bc718b..a51eaf78cd 100644 --- a/packages/flutter_tools/lib/src/commands/generate_localizations.dart +++ b/packages/flutter_tools/lib/src/commands/generate_localizations.dart @@ -9,9 +9,7 @@ import '../base/common.dart'; import '../base/file_system.dart'; import '../base/io.dart'; import '../base/logger.dart'; -import '../globals.dart' as globals; import '../localizations/gen_l10n.dart'; -import '../localizations/gen_l10n_types.dart'; import '../localizations/localizations_utils.dart'; import '../runner/flutter_command.dart'; @@ -34,7 +32,6 @@ class GenerateLocalizationsCommand extends FlutterCommand { _processManager = processManager { argParser.addOption( 'arb-dir', - defaultsTo: globals.fs.path.join('lib', 'l10n'), help: 'The directory where the template and translated arb files are located.', ); argParser.addOption( @@ -51,13 +48,11 @@ class GenerateLocalizationsCommand extends FlutterCommand { ); argParser.addOption( 'template-arb-file', - defaultsTo: 'app_en.arb', help: 'The template arb file that will be used as the basis for ' 'generating the Dart localization and messages files.', ); argParser.addOption( 'output-localization-file', - defaultsTo: 'app_localizations.dart', help: 'The filename for the output localization and localizations ' 'delegate classes.', ); @@ -224,15 +219,19 @@ class GenerateLocalizationsCommand extends FlutterCommand { @override Future runCommand() async { - final List outputFileList; - File? untranslatedMessagesFile; - - bool format = boolArg('format'); - + // Keep in mind that this is also defined in the following locations: + // 1. flutter_tools/lib/src/build_system/targets/localizations.dart + // 2. flutter_tools/test/general.shard/build_system/targets/localizations_test.dart + // Keep the value consistent in all three locations to ensure behavior is the + // same across "flutter gen-l10n" and "flutter run". + final String defaultArbDir = _fileSystem.path.join('lib', 'l10n'); + // Get all options associated with gen-l10n. + final LocalizationOptions options; if (_fileSystem.file('l10n.yaml').existsSync()) { - final LocalizationOptions options = parseLocalizationsOptions( + options = parseLocalizationsOptionsFromYAML( file: _fileSystem.file('l10n.yaml'), logger: _logger, + defaultArbDir: defaultArbDir, ); _logger.printStatus( 'Because l10n.yaml exists, the options defined there will be used ' @@ -240,69 +239,25 @@ class GenerateLocalizationsCommand extends FlutterCommand { 'To use the command line arguments, delete the l10n.yaml file in the ' 'Flutter project.\n\n' ); - final LocalizationsGenerator generator = generateLocalizations( - logger: _logger, - options: options, - projectDir: _fileSystem.currentDirectory, - fileSystem: _fileSystem, - ); - outputFileList = generator.outputFileList; - untranslatedMessagesFile = generator.untranslatedMessagesFile; - format = format || options.format; } else { - final String inputPathString = stringArg('arb-dir')!; // Has default value, cannot be null. - final String? outputPathString = stringArg('output-dir'); - final String outputFileString = stringArg('output-localization-file')!; // Has default value, cannot be null. - final String templateArbFileName = stringArg('template-arb-file')!; // Has default value, cannot be null. - final String? untranslatedMessagesFilePath = stringArg('untranslated-messages-file'); - final String classNameString = stringArg('output-class')!; // Has default value, cannot be null. - final List preferredSupportedLocales = stringsArg('preferred-supported-locales'); - final String? headerString = stringArg('header'); - final String? headerFile = stringArg('header-file'); - final bool useDeferredLoading = boolArg('use-deferred-loading'); - final String? inputsAndOutputsListPath = stringArg('gen-inputs-and-outputs-list'); - final bool useSyntheticPackage = boolArg('synthetic-package'); - final String? projectPathString = stringArg('project-dir'); - final bool areResourceAttributesRequired = boolArg('required-resource-attributes'); - final bool usesNullableGetter = boolArg('nullable-getter'); - final bool useEscaping = boolArg('use-escaping'); - final bool suppressWarnings = boolArg('suppress-warnings'); - - precacheLanguageAndRegionTags(); - - try { - final LocalizationsGenerator generator = LocalizationsGenerator( - fileSystem: _fileSystem, - inputPathString: inputPathString, - outputPathString: outputPathString, - templateArbFileName: templateArbFileName, - outputFileString: outputFileString, - classNameString: classNameString, - preferredSupportedLocales: preferredSupportedLocales, - headerString: headerString, - headerFile: headerFile, - useDeferredLoading: useDeferredLoading, - inputsAndOutputsListPath: inputsAndOutputsListPath, - useSyntheticPackage: useSyntheticPackage, - projectPathString: projectPathString, - areResourceAttributesRequired: areResourceAttributesRequired, - untranslatedMessagesFile: untranslatedMessagesFilePath, - usesNullableGetter: usesNullableGetter, - useEscaping: useEscaping, - logger: _logger, - suppressWarnings: suppressWarnings, - ) - ..loadResources() - ..writeOutputFiles(); - outputFileList = generator.outputFileList; - untranslatedMessagesFile = generator.untranslatedMessagesFile; - } on L10nException catch (e) { - throwToolExit(e.message); - } + options = parseLocalizationsOptionsFromCommand( + command: this, + defaultArbDir: defaultArbDir + ); } + // Run the localizations generator. + final LocalizationsGenerator generator = generateLocalizations( + logger: _logger, + options: options, + projectDir: _fileSystem.currentDirectory, + fileSystem: _fileSystem, + ); + final List outputFileList = generator.outputFileList; + final File? untranslatedMessagesFile = generator.untranslatedMessagesFile; + // All other post processing. - if (format) { + if (options.format) { if (outputFileList.isEmpty) { return FlutterCommandResult.success(); } diff --git a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart index 5e2f9f805d..bd8ea9f03c 100644 --- a/packages/flutter_tools/lib/src/localizations/gen_l10n.dart +++ b/packages/flutter_tools/lib/src/localizations/gen_l10n.dart @@ -30,7 +30,7 @@ LocalizationsGenerator generateLocalizations({ fileSystem: projectDir.fileSystem, logger: logger, ); - if (options.useSyntheticPackage && (flutterManifest == null || !flutterManifest.generateSyntheticPackage)) { + if (options.syntheticPackage && (flutterManifest == null || !flutterManifest.generateSyntheticPackage)) { throwToolExit( 'Attempted to generate localizations code without having ' 'the flutter: generate flag turned on.' @@ -43,28 +43,25 @@ LocalizationsGenerator generateLocalizations({ precacheLanguageAndRegionTags(); - final String inputPathString = options.arbDirectory?.path ?? fileSystem.path.join('lib', 'l10n'); - final String templateArbFileName = options.templateArbFile?.toFilePath() ?? 'app_en.arb'; - final String outputFileString = options.outputLocalizationsFile?.toFilePath() ?? 'app_localizations.dart'; LocalizationsGenerator generator; try { generator = LocalizationsGenerator( fileSystem: fileSystem, inputsAndOutputsListPath: dependenciesDir?.path, projectPathString: projectDir.path, - inputPathString: inputPathString, - templateArbFileName: templateArbFileName, - outputFileString: outputFileString, - outputPathString: options.outputDirectory?.path, - classNameString: options.outputClass ?? 'AppLocalizations', + inputPathString: options.arbDir, + templateArbFileName: options.templateArbFile, + outputFileString: options.outputLocalizationFile, + outputPathString: options.outputDir, + classNameString: options.outputClass, preferredSupportedLocales: options.preferredSupportedLocales, headerString: options.header, - headerFile: options.headerFile?.toFilePath(), - useDeferredLoading: options.deferredLoading ?? false, - useSyntheticPackage: options.useSyntheticPackage, - areResourceAttributesRequired: options.areResourceAttributesRequired, - untranslatedMessagesFile: options.untranslatedMessagesFile?.toFilePath(), - usesNullableGetter: options.usesNullableGetter, + headerFile: options.headerFile, + useDeferredLoading: options.useDeferredLoading, + useSyntheticPackage: options.syntheticPackage, + areResourceAttributesRequired: options.requiredResourceAttributes, + untranslatedMessagesFile: options.untranslatedMessagesFile, + usesNullableGetter: options.nullableGetter, useEscaping: options.useEscaping, logger: logger, suppressWarnings: options.suppressWarnings, diff --git a/packages/flutter_tools/lib/src/localizations/localizations_utils.dart b/packages/flutter_tools/lib/src/localizations/localizations_utils.dart index 08bd615f1e..329f425a9b 100644 --- a/packages/flutter_tools/lib/src/localizations/localizations_utils.dart +++ b/packages/flutter_tools/lib/src/localizations/localizations_utils.dart @@ -8,6 +8,7 @@ import 'package:yaml/yaml.dart'; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/logger.dart'; +import '../runner/flutter_command.dart'; import 'gen_l10n_types.dart'; import 'language_subtag_registry.dart'; @@ -334,89 +335,111 @@ String generateReturnExpr(List expressions, { bool isSingleStringVar = f /// Typed configuration from the localizations config file. class LocalizationOptions { - const LocalizationOptions({ - this.arbDirectory, - this.templateArbFile, - this.outputLocalizationsFile, + LocalizationOptions({ + required this.arbDir, + this.outputDir, + String? templateArbFile, + String? outputLocalizationFile, this.untranslatedMessagesFile, - this.header, - this.outputClass, - this.outputDirectory, + String? outputClass, this.preferredSupportedLocales, + this.header, this.headerFile, - this.deferredLoading, - this.useSyntheticPackage = true, - this.areResourceAttributesRequired = false, - this.usesNullableGetter = true, - this.format = false, - this.useEscaping = false, - this.suppressWarnings = false, - }); + bool? useDeferredLoading, + this.genInputsAndOutputsList, + bool? syntheticPackage, + this.projectDir, + bool? requiredResourceAttributes, + bool? nullableGetter, + bool? format, + bool? useEscaping, + bool? suppressWarnings, + }) : templateArbFile = templateArbFile ?? 'app_en.arb', + outputLocalizationFile = outputLocalizationFile ?? 'app_localizations.dart', + outputClass = outputClass ?? 'AppLocalizations', + useDeferredLoading = useDeferredLoading ?? false, + syntheticPackage = syntheticPackage ?? true, + requiredResourceAttributes = requiredResourceAttributes ?? false, + nullableGetter = nullableGetter ?? true, + format = format ?? false, + useEscaping = useEscaping ?? false, + suppressWarnings = suppressWarnings ?? false; /// The `--arb-dir` argument. /// /// The directory where all input localization files should reside. - final Uri? arbDirectory; + final String arbDir; + + /// The `--output-dir` argument. + /// + /// The directory where all output localization files should be generated. + final String? outputDir; + /// The `--template-arb-file` argument. /// - /// This URI is relative to [arbDirectory]. - final Uri? templateArbFile; + /// This path is relative to [arbDirectory]. + final String templateArbFile; /// The `--output-localization-file` argument. /// - /// This URI is relative to [arbDirectory]. - final Uri? outputLocalizationsFile; + /// This path is relative to [arbDir]. + final String outputLocalizationFile; /// The `--untranslated-messages-file` argument. /// - /// This URI is relative to [arbDirectory]. - final Uri? untranslatedMessagesFile; + /// This path is relative to [arbDir]. + final String? untranslatedMessagesFile; + + /// The `--output-class` argument. + final String outputClass; + + /// The `--preferred-supported-locales` argument. + final List? preferredSupportedLocales; /// The `--header` argument. /// /// The header to prepend to the generated Dart localizations. final String? header; - /// The `--output-class` argument. - final String? outputClass; - - /// The `--output-dir` argument. - /// - /// The directory where all output localization files should be generated. - final Uri? outputDirectory; - - /// The `--preferred-supported-locales` argument. - final List? preferredSupportedLocales; - /// The `--header-file` argument. /// /// A file containing the header to prepend to the generated /// Dart localizations. - final Uri? headerFile; + final String? headerFile; /// The `--use-deferred-loading` argument. /// /// Whether to generate the Dart localization file with locales imported /// as deferred. - final bool? deferredLoading; + final bool useDeferredLoading; + + /// The `--gen-inputs-and-outputs-list` argument. + /// + /// This path is relative to [arbDir]. + final String? genInputsAndOutputsList; /// The `--synthetic-package` argument. /// /// Whether to generate the Dart localization files in a synthetic package /// or in a custom directory. - final bool useSyntheticPackage; + final bool syntheticPackage; + + /// The `--project-dir` argument. + /// + /// This path is relative to [arbDir]. + final String? projectDir; /// The `required-resource-attributes` argument. /// /// Whether to require all resource ids to contain a corresponding /// resource attribute. - final bool areResourceAttributesRequired; + final bool requiredResourceAttributes; /// The `nullable-getter` argument. /// /// Whether or not the localizations class getter is nullable. - final bool usesNullableGetter; + final bool nullableGetter; /// The `format` argument. /// @@ -439,13 +462,14 @@ class LocalizationOptions { /// Throws [Exception] if any of the contents are invalid. Returns a /// [LocalizationOptions] with all fields as `null` if the config file exists /// but is empty. -LocalizationOptions parseLocalizationsOptions({ +LocalizationOptions parseLocalizationsOptionsFromYAML({ required File file, required Logger logger, + required String defaultArbDir, }) { final String contents = file.readAsStringSync(); if (contents.trim().isEmpty) { - return const LocalizationOptions(); + return LocalizationOptions(arbDir: defaultArbDir); } final YamlNode yamlNode; try { @@ -458,22 +482,48 @@ LocalizationOptions parseLocalizationsOptions({ throw Exception(); } return LocalizationOptions( - arbDirectory: _tryReadUri(yamlNode, 'arb-dir', logger), - templateArbFile: _tryReadUri(yamlNode, 'template-arb-file', logger), - outputLocalizationsFile: _tryReadUri(yamlNode, 'output-localization-file', logger), - untranslatedMessagesFile: _tryReadUri(yamlNode, 'untranslated-messages-file', logger), - header: _tryReadString(yamlNode, 'header', logger), + arbDir: _tryReadUri(yamlNode, 'arb-dir', logger)?.path ?? defaultArbDir, + outputDir: _tryReadUri(yamlNode, 'output-dir', logger)?.path, + templateArbFile: _tryReadUri(yamlNode, 'template-arb-file', logger)?.path, + outputLocalizationFile: _tryReadUri(yamlNode, 'output-localization-file', logger)?.path, + untranslatedMessagesFile: _tryReadUri(yamlNode, 'untranslated-messages-file', logger)?.path, outputClass: _tryReadString(yamlNode, 'output-class', logger), - outputDirectory: _tryReadUri(yamlNode, 'output-dir', logger), + header: _tryReadString(yamlNode, 'header', logger), + headerFile: _tryReadUri(yamlNode, 'header-file', logger)?.path, + useDeferredLoading: _tryReadBool(yamlNode, 'use-deferred-loading', logger), preferredSupportedLocales: _tryReadStringList(yamlNode, 'preferred-supported-locales', logger), - headerFile: _tryReadUri(yamlNode, 'header-file', logger), - deferredLoading: _tryReadBool(yamlNode, 'use-deferred-loading', logger), - useSyntheticPackage: _tryReadBool(yamlNode, 'synthetic-package', logger) ?? true, - areResourceAttributesRequired: _tryReadBool(yamlNode, 'required-resource-attributes', logger) ?? false, - usesNullableGetter: _tryReadBool(yamlNode, 'nullable-getter', logger) ?? true, - format: _tryReadBool(yamlNode, 'format', logger) ?? false, - useEscaping: _tryReadBool(yamlNode, 'use-escaping', logger) ?? false, - suppressWarnings: _tryReadBool(yamlNode, 'suppress-warnings', logger) ?? false, + syntheticPackage: _tryReadBool(yamlNode, 'synthetic-package', logger), + requiredResourceAttributes: _tryReadBool(yamlNode, 'required-resource-attributes', logger), + nullableGetter: _tryReadBool(yamlNode, 'nullable-getter', logger), + format: _tryReadBool(yamlNode, 'format', logger), + useEscaping: _tryReadBool(yamlNode, 'use-escaping', logger), + suppressWarnings: _tryReadBool(yamlNode, 'suppress-warnings', logger), + ); +} + +/// Parse the localizations configuration from [FlutterCommand]. +LocalizationOptions parseLocalizationsOptionsFromCommand({ + required FlutterCommand command, + required String defaultArbDir, +}) { + return LocalizationOptions( + arbDir: command.stringArg('arb-dir') ?? defaultArbDir, + outputDir: command.stringArg('output-dir'), + outputLocalizationFile: command.stringArg('output-localization-file'), + templateArbFile: command.stringArg('template-arb-file'), + untranslatedMessagesFile: command.stringArg('untranslated-messages-file'), + outputClass: command.stringArg('output-class'), + header: command.stringArg('header'), + headerFile: command.stringArg('header-file'), + useDeferredLoading: command.boolArg('use-deferred-loading'), + genInputsAndOutputsList: command.stringArg('gen-inputs-and-outputs-list'), + syntheticPackage: command.boolArg('synthetic-package'), + projectDir: command.stringArg('project-dir'), + requiredResourceAttributes: command.boolArg('required-resource-attributes'), + nullableGetter: command.boolArg('nullable-getter'), + format: command.boolArg('format'), + useEscaping: command.boolArg('use-escaping'), + suppressWarnings: command.boolArg('suppress-warnings'), ); } diff --git a/packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart b/packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart index ac1695cfad..a1ac916a80 100644 --- a/packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart +++ b/packages/flutter_tools/test/commands.shard/hermetic/generate_localizations_test.dart @@ -42,6 +42,8 @@ void main() { "description": "Sample description" } }'''); + final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync(); + pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec); final GenerateLocalizationsCommand command = GenerateLocalizationsCommand( fileSystem: fileSystem, logger: logger, @@ -192,6 +194,8 @@ void main() { "description": "Sample description" } }'''); + final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync(); + pubspecFile.writeAsStringSync(BasicProjectWithFlutterGen().pubspec); processManager.addCommand( const FakeCommand( command: [ @@ -351,4 +355,83 @@ untranslated-messages-file: lib/l10n/untranslated.json FileSystem: () => fileSystem, ProcessManager: () => FakeProcessManager.any(), }); + + testUsingContext('throw when generate: false and uses synthetic package when run with 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" + } +}'''); + fileSystem.file('l10n.yaml').createSync(); + final File pubspecFile = fileSystem.file('pubspec.yaml')..createSync(); + pubspecFile.writeAsStringSync(''' + name: test + environment: + sdk: '>=3.0.0-0 <4.0.0' + + dependencies: + flutter: + sdk: flutter + + flutter: + generate: false + '''); + final GenerateLocalizationsCommand command = GenerateLocalizationsCommand( + fileSystem: fileSystem, + logger: logger, + artifacts: artifacts, + processManager: processManager, + ); + expect( + () async => createTestCommandRunner(command).run(['gen-l10n']), + throwsToolExit(message: 'Attempted to generate localizations code without having the flutter: generate flag turned on.') + ); + + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.any(), + }); + + testUsingContext('throw when generate: false and uses synthetic package when run via commandline options', () 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(''' + name: test + environment: + sdk: '>=3.0.0-0 <4.0.0' + + dependencies: + flutter: + sdk: flutter + + flutter: + generate: false + '''); + final GenerateLocalizationsCommand command = GenerateLocalizationsCommand( + fileSystem: fileSystem, + logger: logger, + artifacts: artifacts, + processManager: processManager, + ); + expect( + () async => createTestCommandRunner(command).run(['gen-l10n', '--synthetic-package']), + throwsToolExit(message: 'Attempted to generate localizations code without having the flutter: generate flag turned on.') + ); + + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => FakeProcessManager.any(), + }); } diff --git a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart index 3bc5a9baba..87c9957efd 100644 --- a/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/build_system/targets/localizations_test.dart @@ -49,23 +49,24 @@ required-resource-attributes: false nullable-getter: false '''); - final LocalizationOptions options = parseLocalizationsOptions( + final LocalizationOptions options = parseLocalizationsOptionsFromYAML( file: configFile, logger: BufferLogger.test(), + defaultArbDir: fileSystem.path.join('lib', 'l10n'), ); - expect(options.arbDirectory, Uri.parse('arb')); - expect(options.templateArbFile, Uri.parse('example.arb')); - expect(options.outputLocalizationsFile, Uri.parse('bar')); - expect(options.untranslatedMessagesFile, Uri.parse('untranslated')); + expect(options.arbDir, Uri.parse('arb').path); + expect(options.templateArbFile, Uri.parse('example.arb').path); + expect(options.outputLocalizationFile, Uri.parse('bar').path); + expect(options.untranslatedMessagesFile, Uri.parse('untranslated').path); expect(options.outputClass, 'Foo'); - expect(options.headerFile, Uri.parse('header')); + expect(options.headerFile, Uri.parse('header').path); expect(options.header, 'HEADER'); - expect(options.deferredLoading, true); + expect(options.useDeferredLoading, true); expect(options.preferredSupportedLocales, ['en_US']); - expect(options.useSyntheticPackage, false); - expect(options.areResourceAttributesRequired, false); - expect(options.usesNullableGetter, false); + expect(options.syntheticPackage, false); + expect(options.requiredResourceAttributes, false); + expect(options.nullableGetter, false); }); testWithoutContext('parseLocalizationsOptions handles preferredSupportedLocales as list', () async { @@ -74,9 +75,10 @@ nullable-getter: false preferred-supported-locales: ['en_US', 'de'] '''); - final LocalizationOptions options = parseLocalizationsOptions( + final LocalizationOptions options = parseLocalizationsOptionsFromYAML( file: configFile, logger: BufferLogger.test(), + defaultArbDir: fileSystem.path.join('lib', 'l10n'), ); expect(options.preferredSupportedLocales, ['en_US', 'de']); @@ -91,9 +93,10 @@ use-deferred-loading: string '''); expect( - () => parseLocalizationsOptions( + () => parseLocalizationsOptionsFromYAML( file: configFile, logger: BufferLogger.test(), + defaultArbDir: fileSystem.path.join('lib', 'l10n'), ), throwsException, ); @@ -106,9 +109,10 @@ template-arb-file: {name}_en.arb '''); expect( - () => parseLocalizationsOptions( + () => parseLocalizationsOptionsFromYAML( file: configFile, logger: BufferLogger.test(), + defaultArbDir: fileSystem.path.join('lib', 'l10n'), ), throwsToolExit(), ); diff --git a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart index 2d9c014f4e..340cca2f83 100644 --- a/packages/flutter_tools/test/general.shard/generate_localizations_test.dart +++ b/packages/flutter_tools/test/general.shard/generate_localizations_test.dart @@ -796,10 +796,10 @@ void main() { generateLocalizations( fileSystem: fs, options: LocalizationOptions( - arbDirectory: Uri.directory(defaultL10nPathString), - outputDirectory: Uri.directory(defaultL10nPathString, windows: false), - templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false), - useSyntheticPackage: false, + arbDir: Uri.directory(defaultL10nPathString).path, + outputDir: Uri.directory(defaultL10nPathString, windows: false).path, + templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false).path, + syntheticPackage: false, ), logger: logger, projectDir: fs.currentDirectory, @@ -811,17 +811,17 @@ void main() { _standardFlutterDirectoryL10nSetup(fs); final LocalizationOptions options = LocalizationOptions( header: 'HEADER', - arbDirectory: Uri.directory(defaultL10nPathString), - deferredLoading: true, + arbDir: Uri.directory(defaultL10nPathString).path, + useDeferredLoading: true, outputClass: 'Foo', - outputLocalizationsFile: Uri.file('bar.dart', windows: false), - outputDirectory: Uri.directory(defaultL10nPathString, windows: false), + outputLocalizationFile: Uri.file('bar.dart', windows: false).path, + outputDir: Uri.directory(defaultL10nPathString, windows: false).path, preferredSupportedLocales: ['es'], - templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false), - untranslatedMessagesFile: Uri.file('untranslated', windows: false), - useSyntheticPackage: false, - areResourceAttributesRequired: true, - usesNullableGetter: false, + templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false).path, + untranslatedMessagesFile: Uri.file('untranslated', windows: false).path, + syntheticPackage: false, + requiredResourceAttributes: true, + nullableGetter: false, ); // Verify that values are correctly passed through the localizations target. @@ -877,14 +877,14 @@ flutter: final LocalizationOptions options = LocalizationOptions( header: 'HEADER', - headerFile: Uri.file('header', windows: false), - arbDirectory: Uri.file('arb', windows: false), - deferredLoading: true, + headerFile: Uri.file('header', windows: false).path, + arbDir: Uri.file('arb', windows: false).path, + useDeferredLoading: true, outputClass: 'Foo', - outputLocalizationsFile: Uri.file('bar', windows: false), + outputLocalizationFile: Uri.file('bar', windows: false).path, preferredSupportedLocales: ['en_US'], - templateArbFile: Uri.file('example.arb', windows: false), - untranslatedMessagesFile: Uri.file('untranslated', windows: false), + templateArbFile: Uri.file('example.arb', windows: false).path, + untranslatedMessagesFile: Uri.file('untranslated', windows: false).path, ); expect( @@ -909,10 +909,10 @@ flutter: generateLocalizations( fileSystem: fs, options: LocalizationOptions( - arbDirectory: Uri.directory(defaultL10nPathString), - outputDirectory: Uri.directory(defaultL10nPathString, windows: false), - templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false), - useSyntheticPackage: false, + arbDir: Uri.directory(defaultL10nPathString).path, + outputDir: Uri.directory(defaultL10nPathString, windows: false).path, + templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false).path, + syntheticPackage: false, ), logger: BufferLogger.test(), projectDir: fs.currentDirectory, @@ -936,10 +936,10 @@ class AppLocalizationsEn extends AppLocalizations { fileSystem: fs, options: LocalizationOptions( header: 'HEADER', - arbDirectory: Uri.directory(defaultL10nPathString), - outputDirectory: Uri.directory(defaultL10nPathString, windows: false), - templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false), - useSyntheticPackage: false, + arbDir: Uri.directory(defaultL10nPathString).path, + outputDir: Uri.directory(defaultL10nPathString, windows: false).path, + templateArbFile: Uri.file(defaultTemplateArbFileName, windows: false).path, + syntheticPackage: false, ), logger: logger, projectDir: fs.currentDirectory,