update:i18n
This commit is contained in:
40
yoyo-getfastmirror/lib/i18n.dart
Normal file
40
yoyo-getfastmirror/lib/i18n.dart
Normal file
@@ -0,0 +1,40 @@
|
||||
// ignore_for_file: avoid_dynamic_calls
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:yoyo_get_fast_mirror/i18n/lang.i18n.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n/lang_zh-CN.i18n.dart';
|
||||
|
||||
final local = Platform.environment['LANG'] == 'zh_CN.utf8';
|
||||
final lang = local ? zhCN : enUS;
|
||||
|
||||
class Error {
|
||||
static String network =
|
||||
lang['GetfastmirroCommand']['Error']['NetWork'] as String;
|
||||
static String generateConfig =
|
||||
lang['GetfastmirroCommand']['Error']['GenerateConfig'] as String;
|
||||
}
|
||||
|
||||
class GetfastmirroCommand {
|
||||
static String description =
|
||||
lang['GetfastmirroCommand']['Description'] as String;
|
||||
static String flagOnlyTestHlep =
|
||||
lang['GetfastmirroCommand']['FlagOnlyTestHlep'] as String;
|
||||
static String runOutPut = lang['GetfastmirroCommand']['RunOutPut'] as String;
|
||||
static String writting = lang['GetfastmirroCommand']['Writting'] as String;
|
||||
static String done = lang['GetfastmirroCommand']['Done'] as String;
|
||||
static String speedTest = lang['GetfastmirroCommand']['SpeedTest'] as String;
|
||||
static String speedResult =
|
||||
lang['GetfastmirroCommand']['SpeedResult'] as String;
|
||||
static Error error = Error();
|
||||
}
|
||||
|
||||
class Lang {
|
||||
static String description = lang['Description'] as String;
|
||||
static String flagVersionHlep =lang['FlagVersionHlep'] as String;
|
||||
static String flagVerboseHlep =lang['FlagVerboseHlep'] as String;
|
||||
static String argumentinformation =lang['Argumentinformation'] as String;
|
||||
static String topLevelOptions =lang['TopLevelOptions'] as String;
|
||||
static String command =lang['Command'] as String;
|
||||
static String commandOptions =lang['CommandOptions'] as String;
|
||||
static GetfastmirroCommand getfastmirroCommand = GetfastmirroCommand();
|
||||
}
|
||||
23
yoyo-getfastmirror/lib/i18n/lang.i18n.dart
Normal file
23
yoyo-getfastmirror/lib/i18n/lang.i18n.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
Map<dynamic,dynamic> enUS = {
|
||||
'Description': 'A Very Good aptss created by Yoyo.',
|
||||
'FlagVersionHlep': 'Print the current version.',
|
||||
'FlagVerboseHlep': 'Noisy logging, including all shell commands executed.',
|
||||
'Argumentinformation': 'Argument information:',
|
||||
'TopLevelOptions': ' Top level options:',
|
||||
'Command': ' Command:',
|
||||
'CommandOptions': ' Command options:',
|
||||
'GetfastmirroCommand': {
|
||||
'Description': 'Get fastest mirror and generate config file for oyo',
|
||||
'FlagOnlyTestHlep': "Only test mirrors' speed",
|
||||
'RunOutPut':
|
||||
'Get the fastest mirror which will be write into source file\nAnd generate a config file for oyo',
|
||||
'Error': {
|
||||
'NetWork': 'NetWork Error',
|
||||
'GenerateConfig': 'Generate Config File Error'
|
||||
},
|
||||
'Writting': 'Writting',
|
||||
'Done': 'Done',
|
||||
'SpeedTest': 'Speed Test......',
|
||||
'SpeedResult': 'Speed Result:'
|
||||
}
|
||||
};
|
||||
19
yoyo-getfastmirror/lib/i18n/lang_zh-CN.i18n.dart
Normal file
19
yoyo-getfastmirror/lib/i18n/lang_zh-CN.i18n.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
Map<dynamic,dynamic> zhCN = {
|
||||
'Description': '一个Yoyo OS定制版aptss配置器',
|
||||
'FlagVersionHlep': '打印当前cli的版本',
|
||||
'FlagVerboseHlep': '啰嗦模式',
|
||||
'Argumentinformation': '参数信息:',
|
||||
'TopLevelOptions': ' 顶级选项:',
|
||||
'Command': ' 命令:',
|
||||
'CommandOptions': ' 命令选项:',
|
||||
'GetfastmirroCommand': {
|
||||
'Description': '切换最快的镜像源并为oyo生成配置文件',
|
||||
'FlagOnlyTestHlep': '只测试镜像源速度,不生成配置',
|
||||
'RunOutPut': '切换最快的镜像源并为oyo生成配置文件',
|
||||
'Error': {'NetWork': '网络错误', 'GenerateConfig': '生成文件失败'},
|
||||
'Writting': '写入中',
|
||||
'Done': '完成',
|
||||
'SpeedTest': '速度测试中......',
|
||||
'SpeedResult': '测速结果:'
|
||||
}
|
||||
};
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/commands.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/version.dart';
|
||||
|
||||
const executableName = 'yoyo-getfastmirror';
|
||||
const packageName = 'yoyo_get_fast_mirror';
|
||||
const description = 'A Very Good aptss created by Yoyo.';
|
||||
final description = Lang.description;
|
||||
|
||||
class YoyoGetFastMirrorCommandRunner extends CommandRunner<int> {
|
||||
/// {@macro yoyo_get_fast_mirror_command_runner}
|
||||
@@ -20,15 +21,15 @@ class YoyoGetFastMirrorCommandRunner extends CommandRunner<int> {
|
||||
'version',
|
||||
abbr: 'v',
|
||||
negatable: false,
|
||||
help: 'Print the current version.',
|
||||
help: Lang.flagVersionHlep,
|
||||
)
|
||||
..addFlag(
|
||||
'verbose',
|
||||
help: 'Noisy logging, including all shell commands executed.',
|
||||
help: Lang.flagVerboseHlep,
|
||||
);
|
||||
|
||||
// Add sub commands
|
||||
addCommand(GetfastmirroCommand(logger: _logger));
|
||||
addCommand(GetfastmirrorCommand(logger: _logger));
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -67,8 +68,8 @@ class YoyoGetFastMirrorCommandRunner extends CommandRunner<int> {
|
||||
@override
|
||||
Future<int?> runCommand(ArgResults topLevelResults) async {
|
||||
_logger
|
||||
..detail('Argument information:')
|
||||
..detail(' Top level options:');
|
||||
..detail(Lang.argumentinformation)
|
||||
..detail(Lang.topLevelOptions);
|
||||
for (final option in topLevelResults.options) {
|
||||
if (topLevelResults.wasParsed(option)) {
|
||||
_logger.detail(' - $option: ${topLevelResults[option]}');
|
||||
@@ -77,8 +78,8 @@ class YoyoGetFastMirrorCommandRunner extends CommandRunner<int> {
|
||||
if (topLevelResults.command != null) {
|
||||
final commandResult = topLevelResults.command!;
|
||||
_logger
|
||||
..detail(' Command: ${commandResult.name}')
|
||||
..detail(' Command options:');
|
||||
..detail('${Lang.command} ${commandResult.name}')
|
||||
..detail(Lang.commandOptions);
|
||||
for (final option in commandResult.options) {
|
||||
if (commandResult.wasParsed(option)) {
|
||||
_logger.detail(' - $option: ${commandResult[option]}');
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/getfastmirror.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/getfastmirror.dart';
|
||||
|
||||
class GetfastmirroCommand extends Command<int> {
|
||||
GetfastmirroCommand({
|
||||
class GetfastmirrorCommand extends Command<int> {
|
||||
GetfastmirrorCommand({
|
||||
required Logger logger,
|
||||
}) : _logger = logger {
|
||||
argParser.addFlag(
|
||||
'only-test',
|
||||
abbr: 'o',
|
||||
help: "Only test mirrors' speed",
|
||||
help: GetfastmirroCommand.flagOnlyTestHlep,
|
||||
negatable: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String get description =>
|
||||
'Get fastest mirror and generate config file for oyo';
|
||||
String get description => GetfastmirroCommand.description;
|
||||
|
||||
@override
|
||||
String get name => 'getfastmirror';
|
||||
@@ -25,10 +25,7 @@ class GetfastmirroCommand extends Command<int> {
|
||||
|
||||
@override
|
||||
Future<int> run() async {
|
||||
final output = lightBlue.wrap('''
|
||||
Get the fastest mirror which will be write into source file
|
||||
And generate a config file for oyo
|
||||
''');
|
||||
final output = lightBlue.wrap(GetfastmirroCommand.runOutPut);
|
||||
_logger.info(output);
|
||||
final onlyTest = argResults?['only-test'] == true;
|
||||
final commandResult = await getFastMirror(onlyTest: onlyTest);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Ubuntu/ubuntu_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Yoyo/yoyo_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/Yoyo/yoyo_is_exist.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/generate_apt_fast_config_file.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/network_test.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/test_mirro_speed.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/write_mirror_into_file.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/Ubuntu/ubuntu_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/Yoyo/yoyo_get_mirro_list.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/Yoyo/yoyo_is_exist.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/utils/generate_apt_fast_config_file.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/utils/network_test.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/utils/test_mirro_speed.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/utils/write_mirror_into_file.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n.dart';
|
||||
|
||||
final Map<String, dynamic> status = {};
|
||||
final Logger _logger = Logger();
|
||||
@@ -17,7 +18,7 @@ Future<Map<String, dynamic>> getFastMirror({bool onlyTest = false}) async {
|
||||
//首先测试网络链接
|
||||
if (!await networkTest()) {
|
||||
status['success'] = false;
|
||||
status['msg'] = 'NetWork Error';
|
||||
status['msg'] = Error.network;
|
||||
return status;
|
||||
}
|
||||
// 如果 yoyo-os.list 存在,获取Yoyo镜像地址
|
||||
@@ -45,7 +46,7 @@ Future<Map<String, dynamic>> getFastMirror({bool onlyTest = false}) async {
|
||||
);
|
||||
} catch (e) {
|
||||
status['success'] = false;
|
||||
status['msg'] = 'Generate Config File Error';
|
||||
status['msg'] = Error.generateConfig;
|
||||
return status;
|
||||
} finally {
|
||||
status['success'] = true;
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'dart:io';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirro/utils/apt_fast_config_template.dart';
|
||||
import 'package:yoyo_get_fast_mirror/src/commands/modules/getfastmirror/utils/apt_fast_config_template.dart';
|
||||
|
||||
final tmpDir = Directory.systemTemp.path;
|
||||
final String filePath = '$tmpDir/oyo/apt-fast.conf';
|
||||
@@ -3,15 +3,16 @@ import 'dart:collection';
|
||||
import 'package:cli_spinner/cli_spinner.dart';
|
||||
import 'package:dart_ping/dart_ping.dart';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n.dart';
|
||||
|
||||
Logger _logger = Logger();
|
||||
final speedResult = lightGreen.wrap('Speed Result:');
|
||||
final speedResult = lightGreen.wrap(GetfastmirroCommand.speedResult);
|
||||
|
||||
Future<List<Map<String, String>>> testMirroSpeed(
|
||||
List<String> mirrorList,
|
||||
) async {
|
||||
final spinner =
|
||||
Spinner.type('Speed Test ......', SpinnerType.boxCircle)..start();
|
||||
Spinner.type(GetfastmirroCommand.speedTest, SpinnerType.boxCircle)..start();
|
||||
final testResult = <Map<String, String>>[];
|
||||
final logMsg = StringBuffer()..write(speedResult);
|
||||
for (final element in mirrorList) {
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'dart:io';
|
||||
import 'package:mason_logger/mason_logger.dart';
|
||||
import 'package:yoyo_get_fast_mirror/i18n.dart';
|
||||
|
||||
final done = lightGreen.wrap('Done');
|
||||
final done = lightGreen.wrap(GetfastmirroCommand.done);
|
||||
final Logger _logger = Logger();
|
||||
RegExp urlReg = RegExp(
|
||||
r'\b(([\w-]+://?|www[.])[^\s()<>]+(?:[\w\d]+|([^[:punct:]\s]|/)))',
|
||||
@@ -9,7 +10,7 @@ RegExp urlReg = RegExp(
|
||||
|
||||
///mirror 镜像源网址
|
||||
void writeMirrorIntoFile(String mirror, String path) {
|
||||
final writting = lightYellow.wrap('Writting $path');
|
||||
final writting = lightYellow.wrap('${GetfastmirroCommand.writting} $path');
|
||||
final file = File(path);
|
||||
var fileContent = file.readAsStringSync();
|
||||
final url = urlReg.allMatches(fileContent);
|
||||
@@ -1 +1 @@
|
||||
const packageVersion = '2023.1.31';
|
||||
const packageVersion = '2023.1.31-2';
|
||||
|
||||
Reference in New Issue
Block a user