addLang static method
Implementation
static Future<void> addLang({List<String>? languages}) async {
if (languages == null) {
stdout.write(
"${ColorsText.blue}Enter app languages (e.g., ar,en): ${ColorsText.reset}");
languages = stdin.readLineSync()?.split(',') ?? ['ar'];
}
String content = await CreatorUtil.readFileContent(
'${Directory.current.path}/pubspec.yaml');
if (!content.contains('flutter_localizations')) {
content = content.replaceFirst(
'dependencies:', '''dependencies:\n flutter_localizations:
sdk: flutter''');
CreatorUtil.editFileContent(
'${Directory.current.path}/pubspec.yaml', '$content generate: true',
canFormated: false);
}
CreatorUtil.createDirectory('$path/l10n');
for (String code in languages) {
CreatorUtil.createFileWithContent(
'$path/l10n/app_$code.arb', '{"home":"$code"}',
canFormated: false);
}
CreatorUtil.createFileWithContent(
'${Directory.current.path}/l10n.yaml',
'''
arb-dir: lib/l10n
template-arb-file: app_ar.arb
output-localization-file: app_localizations.dart
''',
canFormated: false);
}