perf: update the selected service in the configuration file

dev_config
SONGE9B3\song_pd_win11 2 years ago
parent 83235deda4
commit aab8f0d387

@ -46,14 +46,13 @@ namespace STranslate.Helper
/// <summary>
/// 配置文件
/// </summary>
private static string _CnfName { get => $"{_ApplicationData}\\stranslate.json"; }
private static string _CnfName => $"{_ApplicationData}\\{_AppName.ToLower()}.json";
/// <summary>
/// C:\Users\user\AppData\Local\STranslate
/// </summary>
private static readonly string _ApplicationData
= $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}"
+ $"\\{Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)}";
private static string _ApplicationData => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\{_AppName}";
private static readonly string _AppName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
private static ConfigHelper _Instance;
public static ConfigHelper Instance { get => _Instance ?? (_Instance = new ConfigHelper()); }
}

@ -48,8 +48,8 @@
<ComboBox Style="{DynamicResource cmbstyle}"
Margin="0,5,10,0"
ItemsSource="{Binding TranslationInterface}"
SelectedItem="{Binding SelectedTranslationInterface, Mode=TwoWay, NotifyOnSourceUpdated=True}"
DisplayMemberPath="Name"
SelectedItem="{Binding SelectedTranslationInterface}"
HorizontalAlignment="Right"/>
</Grid>

@ -15,18 +15,19 @@ namespace STranslate.Model
public ConfigModel InitialConfig()
{
var defaultServer = new Server
{
Name = "zggsong",
Api = "https://zggsong.cn/tt"
};
return new ConfigModel
{
IsBright = true,
SelectServer = defaultServer,
SourceLanguage = LanguageEnum.AUTO,
TargetLanguage = LanguageEnum.AUTO,
SelectServer = 0,
Servers = new Server[]
{
defaultServer,
new Server
{
Name = "zggsong",
Api = "https://zggsong.cn/tt"
},
new Server
{
Name = "zu1k",
@ -47,8 +48,14 @@ namespace STranslate.Model
[JsonProperty("isBright")]
public bool IsBright { get; set; }
[JsonProperty("sourceLanguage")]
public LanguageEnum SourceLanguage { get; set; }
[JsonProperty("targetLanguage")]
public LanguageEnum TargetLanguage { get; set; }
[JsonProperty("selectServer")]
public Server SelectServer { get; set; }
public int SelectServer { get; set; }
/// <summary>
/// 服务

@ -24,10 +24,6 @@ namespace STranslate.ViewModel
Task.Delay(3000);
Environment.Exit(-1);
}
InputCombo = LanguageEnumDict.Keys.ToList();
InputComboSelected = LanguageEnum.AUTO.GetDescription();
OutputCombo = LanguageEnumDict.Keys.ToList();
OutputComboSelected = LanguageEnum.AUTO.GetDescription();
//复制输入
CopyInputCmd = new RelayCommand((_) => true, (_) =>
@ -83,14 +79,27 @@ namespace STranslate.ViewModel
{
try
{
InputCombo = LanguageEnumDict.Keys.ToList();
OutputCombo = LanguageEnumDict.Keys.ToList();
GlobalConfig = ConfigHelper.Instance.ReadConfig<ConfigModel>();
//更新服务
TranslationInterface = GlobalConfig.Servers.ToList();
if (TranslationInterface.Count < 1) throw new Exception("尚未配置任何翻译接口服务");
//初始化接口
SelectedTranslationInterface = GlobalConfig.SelectServer;
try
{
//配置读取接口
SelectedTranslationInterface = TranslationInterface[GlobalConfig.SelectServer];
}
catch (Exception ex)
{
throw new Exception($"配置文件选择服务索引出错, 请修改配置文件后重试", ex);
}
//从配置读取source target
InputComboSelected = GlobalConfig.SourceLanguage.GetDescription();
OutputComboSelected = GlobalConfig.TargetLanguage.GetDescription();
return true;
}
@ -130,18 +139,8 @@ namespace STranslate.ViewModel
{
return new Tuple<string, string>(LanguageEnum.ZH.GetDescription(), LanguageEnum.EN.GetDescription());
}
#if false
//如果输入是中文
if (Regex.IsMatch(text, @"^[\u4e00-\u9fa5]+$"))
{
return new Tuple<string, string>(LanguageEnum.ZH.GetDescription(), LanguageEnum.EN.GetDescription());
}
else
{
return new Tuple<string, string>(LanguageEnum.EN.GetDescription(), LanguageEnum.ZH.GetDescription());
}
#endif
}
/// <summary>
/// 翻译
/// </summary>

Loading…
Cancel
Save