[gen_l10n] Synthetic package generation by default (#62395)
* synthetic packages by default in gen_l10n tool * Refactor default path for synthetic package * Remove unused import * Code cleanup * Further improvements to help text * Refactor synthetic package path * Remove newlines * Test cleanup * clean up logic in inputs and outputs list function * Update l10n.yaml usage * only add option if value is non-null * Update stocks app as proof of concept for synthetic package usage * Address nits * print pubspec contents * add print statements * Do not allow null value for useSyntheticPackage * + * + * + * + * Cleanup * Add test * Fix text * Dont parse pubspec directly * Test using context * WIP: generate synthetic packages on pub get -- needs tests * Allow null value * Update null handling * Refactor to properly handle null case * Fix yamlMap condition * Fix yaml node for real * WIP: struggling to write tests * WIP - take absolute path as an option * Add tests * Use environment project directory for synthetic package generation pathway * Fix typo * Improve help text * Update defaults * Remove unauthorized path import * Fix pathing issues at synthetic package generation * Fix typo in test * Use path.join so projectDir matches up based on OS * Fix Windows pathing in test * Remove unnecessary replaceApp code for projectDir.path * Use globals.fs.currentDirectory.path in resident_runner_test.dart * Fix merge conflict * Add test to ensure that synthetic package is generated on pub get * Fix resident_runner_test.dart tests * Fix tests * Use package:file instead of dart:io * WIP - exploration * Remove synthetic package use from stocks example * Update integration test to not use synthetic packages * Remove trailing whitespace * flutter pub get runs synth package generation * Remove more print statements * Add license header * WIP - minimally working pub.get * Use own MockBuildSystem * Modify test and implementation to be a little cleaner * Fix flutter pub get invocation * Use synthetic packages in stocks app * Revert "Use synthetic packages in stocks app" This reverts commit 45bf24903c3d4a2a5fd5481d7d6bc36c4a348703. * Add environment and buildSystem params to flutter test * Address code review feedback * + * Isolate codegen into its own API * Fix imports * Slight refactor * Add one more test for no l10n.yaml file * Remove unneeded mock class and import in pub_get_test.dart * More code review feedback * Remove unnecessary imports * Remove `return await`s that I missed * use arrow functions instead
This commit is contained in:
@@ -2,16 +2,17 @@
|
||||
## `arb-dir` sets the input directory. The output directory will match
|
||||
## the input directory if the output directory is not set.
|
||||
arb-dir: lib/i18n
|
||||
## `template-arb-file` describes the template arb file that the tool
|
||||
## will use to check and validate the remaining arb files when
|
||||
## generating Flutter's localization files.
|
||||
template-arb-file: stocks_en.arb
|
||||
## `output-localization-file` is the name of the generated file.
|
||||
output-localization-file: stock_strings.dart
|
||||
## `header-file` is the file that contains a custom
|
||||
## header for each of the generated files.
|
||||
header-file: header.txt
|
||||
## `output-class` is the name of the localizations class your
|
||||
## Flutter application will use. The file will need to be
|
||||
## imported throughout your application.
|
||||
output-class: StockStrings
|
||||
## `header-file` is the file that contains a custom
|
||||
## header for each of the generated files.
|
||||
header-file: header.txt
|
||||
## `output-localization-file` is the name of the generated file.
|
||||
output-localization-file: stock_strings.dart
|
||||
## `template-arb-file` describes the template arb file that the tool
|
||||
## will use to check and validate the remaining arb files when
|
||||
## generating Flutter's localization files.
|
||||
synthetic-package: false
|
||||
template-arb-file: stocks_en.arb
|
||||
|
||||
@@ -27,10 +27,15 @@ void main(List<String> arguments) {
|
||||
);
|
||||
parser.addOption(
|
||||
'output-dir',
|
||||
help: 'The directory where the generated localization classes will be written. '
|
||||
help: 'The directory where the generated localization classes will be written '
|
||||
'if the synthetic-package flag is set to false.'
|
||||
'\n\n'
|
||||
'If output-dir is specified and the synthetic-package flag is enabled, '
|
||||
'this option will be ignored by the tool.'
|
||||
'\n\n'
|
||||
'The app must import the file specified in the \'output-localization-file\' '
|
||||
'option from this directory. If unspecified, this defaults to the same '
|
||||
'directory as the input directory specified in \'arb-dir\'.'
|
||||
'directory as the input directory specified in \'arb-dir\'.',
|
||||
);
|
||||
parser.addOption(
|
||||
'template-arb-file',
|
||||
@@ -120,6 +125,20 @@ void main(List<String> arguments) {
|
||||
'\n\n'
|
||||
'When null, the JSON file will not be generated.'
|
||||
);
|
||||
parser.addFlag(
|
||||
'synthetic-package',
|
||||
defaultsTo: true,
|
||||
help: 'Determines whether or not the generated output files will be '
|
||||
'generated as a synthetic package or at a specified directory in '
|
||||
'the Flutter project.'
|
||||
'\n\n'
|
||||
'This flag is set to true by default.'
|
||||
'\n\n'
|
||||
'When synthetic-package is set to false, it will generate the '
|
||||
'localizations files in the directory specified by arb-dir by default. '
|
||||
'\n\n'
|
||||
'If output-dir is specified, files will be generated there.',
|
||||
);
|
||||
parser.addOption(
|
||||
'project-dir',
|
||||
valueHelp: 'absolute/path/to/flutter/project',
|
||||
@@ -148,6 +167,7 @@ void main(List<String> arguments) {
|
||||
final String headerFile = results['header-file'] as String;
|
||||
final bool useDeferredLoading = results['use-deferred-loading'] as bool;
|
||||
final String inputsAndOutputsListPath = results['gen-inputs-and-outputs-list'] as String;
|
||||
final bool useSyntheticPackage = results['synthetic-package'] as bool;
|
||||
final String projectPathString = results['project-dir'] as String;
|
||||
|
||||
const local.LocalFileSystem fs = local.LocalFileSystem();
|
||||
@@ -166,6 +186,7 @@ void main(List<String> arguments) {
|
||||
headerFile: headerFile,
|
||||
useDeferredLoading: useDeferredLoading,
|
||||
inputsAndOutputsListPath: inputsAndOutputsListPath,
|
||||
useSyntheticPackage: useSyntheticPackage,
|
||||
projectPathString: projectPathString,
|
||||
)
|
||||
..loadResources()
|
||||
|
||||
@@ -13,6 +13,13 @@ import 'gen_l10n_templates.dart';
|
||||
import 'gen_l10n_types.dart';
|
||||
import 'localizations_utils.dart';
|
||||
|
||||
/// The default path used when the `useSyntheticPackage` setting is set to true
|
||||
/// in [LocalizationsGenerator].
|
||||
///
|
||||
/// See [LocalizationsGenerator.initialize] for where and how it is used by the
|
||||
/// localizations tool.
|
||||
final String defaultSyntheticPackagePath = path.join('.dart_tool', 'flutter_gen', 'gen_l10n');
|
||||
|
||||
List<String> generateMethodParameters(Message message) {
|
||||
assert(message.placeholders.isNotEmpty);
|
||||
final Placeholder countPlaceholder = message.isPlural ? message.getCountPlaceholder() : null;
|
||||
@@ -523,11 +530,15 @@ class LocalizationsGenerator {
|
||||
String headerFile,
|
||||
bool useDeferredLoading = false,
|
||||
String inputsAndOutputsListPath,
|
||||
bool useSyntheticPackage = true,
|
||||
String projectPathString,
|
||||
}) {
|
||||
setProjectDir(projectPathString);
|
||||
setInputDirectory(inputPathString);
|
||||
setOutputDirectory(outputPathString ?? inputPathString);
|
||||
setOutputDirectory(
|
||||
outputPathString: outputPathString ?? inputPathString,
|
||||
useSyntheticPackage: useSyntheticPackage,
|
||||
);
|
||||
setTemplateArbFile(templateArbFileName);
|
||||
setBaseOutputFile(outputFileString);
|
||||
setPreferredSupportedLocales(preferredSupportedLocaleString);
|
||||
@@ -595,14 +606,29 @@ class LocalizationsGenerator {
|
||||
|
||||
/// Sets the reference [Directory] for [outputDirectory].
|
||||
@visibleForTesting
|
||||
void setOutputDirectory(String outputPathString) {
|
||||
if (outputPathString == null)
|
||||
throw L10nException('outputPathString argument cannot be null');
|
||||
outputDirectory = _fs.directory(
|
||||
projectDirectory != null
|
||||
? _getAbsoluteProjectPath(outputPathString)
|
||||
: outputPathString
|
||||
);
|
||||
void setOutputDirectory({
|
||||
String outputPathString,
|
||||
bool useSyntheticPackage = true,
|
||||
}) {
|
||||
if (useSyntheticPackage) {
|
||||
outputDirectory = _fs.directory(
|
||||
projectDirectory != null
|
||||
? _getAbsoluteProjectPath(defaultSyntheticPackagePath)
|
||||
: defaultSyntheticPackagePath
|
||||
);
|
||||
} else {
|
||||
if (outputPathString == null)
|
||||
throw L10nException(
|
||||
'outputPathString argument cannot be null if not using '
|
||||
'synthetic package option.'
|
||||
);
|
||||
|
||||
outputDirectory = _fs.directory(
|
||||
projectDirectory != null
|
||||
? _getAbsoluteProjectPath(outputPathString)
|
||||
: outputPathString
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the reference [File] for [templateArbFile].
|
||||
@@ -716,6 +742,7 @@ class LocalizationsGenerator {
|
||||
_inputsAndOutputsListFile = _fs.file(
|
||||
path.join(inputsAndOutputsListPath, 'gen_l10n_inputs_and_outputs.json'),
|
||||
);
|
||||
|
||||
_inputFileList = <String>[];
|
||||
_outputFileList = <String>[];
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import '../../localization/localizations_utils.dart';
|
||||
import '../common.dart';
|
||||
|
||||
final String defaultL10nPathString = path.join('lib', 'l10n');
|
||||
final String syntheticPackagePath = path.join('.dart_tool', 'flutter_gen', 'gen_l10n');
|
||||
const String defaultTemplateArbFileName = 'app_en.arb';
|
||||
const String defaultOutputFileString = 'output-localization-file.dart';
|
||||
const String defaultClassNameString = 'AppLocalizations';
|
||||
@@ -98,21 +99,28 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('setOutputDirectory fails if output string is null', () {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||
try {
|
||||
generator.setOutputDirectory(null);
|
||||
} on L10nException catch (e) {
|
||||
expect(e.message, contains('cannot be null'));
|
||||
return;
|
||||
}
|
||||
test(
|
||||
'setOutputDirectory fails if output string is null while not using the '
|
||||
'synthetic package option',
|
||||
() {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||
try {
|
||||
generator.setOutputDirectory(
|
||||
outputPathString: null,
|
||||
useSyntheticPackage: false,
|
||||
);
|
||||
} on L10nException catch (e) {
|
||||
expect(e.message, contains('cannot be null'));
|
||||
return;
|
||||
}
|
||||
|
||||
fail(
|
||||
'LocalizationsGenerator.setOutputDirectory should fail if the '
|
||||
'input string is null.'
|
||||
);
|
||||
});
|
||||
fail(
|
||||
'LocalizationsGenerator.setOutputDirectory should fail if the '
|
||||
'input string is null.'
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('setTemplateArbFile fails if inputDirectory is null', () {
|
||||
final LocalizationsGenerator generator = LocalizationsGenerator(fs);
|
||||
@@ -232,8 +240,9 @@ void main() {
|
||||
expect(
|
||||
fs.isFileSync(path.join(
|
||||
flutterProjectPath,
|
||||
'lib',
|
||||
'l10n',
|
||||
'.dart_tool',
|
||||
'flutter_gen',
|
||||
'gen_l10n',
|
||||
'output-localization-file_en.dart',
|
||||
)),
|
||||
true,
|
||||
@@ -241,8 +250,9 @@ void main() {
|
||||
expect(
|
||||
fs.isFileSync(path.join(
|
||||
flutterProjectPath,
|
||||
'lib',
|
||||
'l10n',
|
||||
'.dart_tool',
|
||||
'flutter_gen',
|
||||
'gen_l10n',
|
||||
'output-localization-file_es.dart',
|
||||
)),
|
||||
true,
|
||||
@@ -289,7 +299,7 @@ void main() {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
try {
|
||||
generator.setInputDirectory(defaultL10nPathString);
|
||||
generator.setOutputDirectory(defaultL10nPathString);
|
||||
generator.setOutputDirectory();
|
||||
generator.setTemplateArbFile(defaultTemplateArbFileName);
|
||||
generator.setBaseOutputFile(defaultOutputFileString);
|
||||
} on L10nException catch (e) {
|
||||
@@ -420,7 +430,7 @@ void main() {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n');
|
||||
final Directory outputDirectory = fs.directory(syntheticPackagePath);
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
@@ -490,95 +500,111 @@ void main() {
|
||||
expect(unimplementedOutputString, contains('subtitle'));
|
||||
});
|
||||
|
||||
test('uses inputPathString as outputPathString when the outputPathString is null', () {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
test(
|
||||
'uses inputPathString as outputPathString when the outputPathString is '
|
||||
'null while not using the synthetic package option',
|
||||
() {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
// outputPathString is intentionally not defined
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
useSyntheticPackage: false,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n');
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
});
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n');
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('correctly generates output files in non-default output directory if it already exists', () {
|
||||
final Directory l10nDirectory = fs.currentDirectory
|
||||
.childDirectory('lib')
|
||||
.childDirectory('l10n')
|
||||
..createSync(recursive: true);
|
||||
// Create the directory 'lib/l10n/output'.
|
||||
l10nDirectory.childDirectory('output');
|
||||
test(
|
||||
'correctly generates output files in non-default output directory if it '
|
||||
'already exists while not using the synthetic package option',
|
||||
() {
|
||||
final Directory l10nDirectory = fs.currentDirectory
|
||||
.childDirectory('lib')
|
||||
.childDirectory('l10n')
|
||||
..createSync(recursive: true);
|
||||
// Create the directory 'lib/l10n/output'.
|
||||
l10nDirectory.childDirectory('output');
|
||||
|
||||
l10nDirectory
|
||||
.childFile(defaultTemplateArbFileName)
|
||||
.writeAsStringSync(singleMessageArbFileString);
|
||||
l10nDirectory
|
||||
.childFile(esArbFileName)
|
||||
.writeAsStringSync(singleEsMessageArbFileString);
|
||||
l10nDirectory
|
||||
.childFile(defaultTemplateArbFileName)
|
||||
.writeAsStringSync(singleMessageArbFileString);
|
||||
l10nDirectory
|
||||
.childFile(esArbFileName)
|
||||
.writeAsStringSync(singleEsMessageArbFileString);
|
||||
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: path.join('lib', 'l10n', 'output'),
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: path.join('lib', 'l10n', 'output'),
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
useSyntheticPackage: false,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n').childDirectory('output');
|
||||
expect(outputDirectory.existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
});
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n').childDirectory('output');
|
||||
expect(outputDirectory.existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('correctly creates output directory if it does not exist and writes files in it', () {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
test(
|
||||
'correctly creates output directory if it does not exist and writes files '
|
||||
'in it while not using the synthetic package option',
|
||||
() {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: path.join('lib', 'l10n', 'output'),
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
LocalizationsGenerator generator;
|
||||
try {
|
||||
generator = LocalizationsGenerator(fs);
|
||||
generator
|
||||
..initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: path.join('lib', 'l10n', 'output'),
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
useSyntheticPackage: false,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
} on L10nException catch (e) {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n').childDirectory('output');
|
||||
expect(outputDirectory.existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
});
|
||||
final Directory outputDirectory = fs.directory('lib').childDirectory('l10n').childDirectory('output');
|
||||
expect(outputDirectory.existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_en.dart').existsSync(), isTrue);
|
||||
expect(outputDirectory.childFile('output-localization-file_es.dart').existsSync(), isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('creates list of inputs and outputs when file path is specified', () {
|
||||
_standardFlutterDirectoryL10nSetup(fs);
|
||||
@@ -592,7 +618,7 @@ void main() {
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
inputsAndOutputsListPath: defaultL10nPathString,
|
||||
inputsAndOutputsListPath: syntheticPackagePath,
|
||||
)
|
||||
..loadResources()
|
||||
..writeOutputFiles();
|
||||
@@ -600,10 +626,9 @@ void main() {
|
||||
fail('Generating output should not fail: \n${e.message}');
|
||||
}
|
||||
|
||||
final File inputsAndOutputsList = fs
|
||||
.directory('lib')
|
||||
.childDirectory('l10n')
|
||||
.childFile('gen_l10n_inputs_and_outputs.json');
|
||||
final File inputsAndOutputsList = fs.file(
|
||||
path.join(syntheticPackagePath, 'gen_l10n_inputs_and_outputs.json'),
|
||||
);
|
||||
expect(inputsAndOutputsList.existsSync(), isTrue);
|
||||
|
||||
final Map<String, dynamic> jsonResult = json.decode(inputsAndOutputsList.readAsStringSync()) as Map<String, dynamic>;
|
||||
@@ -614,9 +639,9 @@ void main() {
|
||||
|
||||
expect(jsonResult.containsKey('outputs'), isTrue);
|
||||
final List<dynamic> outputList = jsonResult['outputs'] as List<dynamic>;
|
||||
expect(outputList, contains(fs.path.absolute('lib', 'l10n', 'output-localization-file.dart')));
|
||||
expect(outputList, contains(fs.path.absolute('lib', 'l10n', 'output-localization-file_en.dart')));
|
||||
expect(outputList, contains(fs.path.absolute('lib', 'l10n', 'output-localization-file_es.dart')));
|
||||
expect(outputList, contains(fs.path.absolute(syntheticPackagePath, 'output-localization-file.dart')));
|
||||
expect(outputList, contains(fs.path.absolute(syntheticPackagePath, 'output-localization-file_en.dart')));
|
||||
expect(outputList, contains(fs.path.absolute(syntheticPackagePath, 'output-localization-file_es.dart')));
|
||||
});
|
||||
|
||||
test('setting both a headerString and a headerFile should fail', () {
|
||||
@@ -1105,11 +1130,11 @@ void main() {
|
||||
fail('Generating output files should not fail: $e');
|
||||
}
|
||||
|
||||
expect(fs.isFileSync(path.join('lib', 'l10n', 'output-localization-file_en.dart')), true);
|
||||
expect(fs.isFileSync(path.join('lib', 'l10n', 'output-localization-file_en_US.dart')), false);
|
||||
expect(fs.isFileSync(path.join(syntheticPackagePath, 'output-localization-file_en.dart')), true);
|
||||
expect(fs.isFileSync(path.join(syntheticPackagePath, 'output-localization-file_en_US.dart')), false);
|
||||
|
||||
final String englishLocalizationsFile = fs.file(
|
||||
path.join('lib', 'l10n', 'output-localization-file_en.dart')
|
||||
path.join(syntheticPackagePath, 'output-localization-file_en.dart')
|
||||
).readAsStringSync();
|
||||
expect(englishLocalizationsFile, contains('class AppLocalizationsEnCa extends AppLocalizationsEn'));
|
||||
expect(englishLocalizationsFile, contains('class AppLocalizationsEn extends AppLocalizations'));
|
||||
@@ -1139,7 +1164,7 @@ void main() {
|
||||
}
|
||||
|
||||
final String localizationsFile = fs.file(
|
||||
path.join('lib', 'l10n', defaultOutputFileString),
|
||||
path.join(syntheticPackagePath, defaultOutputFileString),
|
||||
).readAsStringSync();
|
||||
expect(localizationsFile, contains(
|
||||
'''
|
||||
@@ -1157,7 +1182,6 @@ import 'output-localization-file_zh.dart';
|
||||
try {
|
||||
generator.initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: defaultL10nPathString,
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
@@ -1170,7 +1194,7 @@ import 'output-localization-file_zh.dart';
|
||||
}
|
||||
|
||||
final String localizationsFile = fs.file(
|
||||
path.join('lib', 'l10n', defaultOutputFileString),
|
||||
path.join(syntheticPackagePath, defaultOutputFileString),
|
||||
).readAsStringSync();
|
||||
expect(localizationsFile, contains(
|
||||
'''
|
||||
@@ -1204,7 +1228,6 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
try {
|
||||
generator.initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: defaultL10nPathString,
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
@@ -1583,7 +1606,6 @@ import 'output-localization-file_en.dart' deferred as output-localization-file_e
|
||||
try {
|
||||
generator.initialize(
|
||||
inputPathString: defaultL10nPathString,
|
||||
outputPathString: defaultL10nPathString,
|
||||
templateArbFileName: defaultTemplateArbFileName,
|
||||
outputFileString: defaultOutputFileString,
|
||||
classNameString: defaultClassNameString,
|
||||
|
||||
Reference in New Issue
Block a user