Skip to content

Commit

Permalink
clean code and others
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Jul 28, 2024
1 parent 00aa190 commit ef8efea
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 32 deletions.
File renamed without changes.
16 changes: 12 additions & 4 deletions SMT.Core/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

public static class Configuration
{
public const string SrcLangPath = "engus";
public const string SrcLangInnerName = "engUS";
public static string SrcLangPath = "engus";
public static string SrcLangInnerName = "engUS";

public static string DestLangPath = "zhocn";
public static string DestLangInnerName = "zhoCN";

public static void UpdateDestLang(string path, string inner)
{
DestLangInnerName = inner;
DestLangPath = path;
}


public const string DestLangPath = "zhocn";
public const string DestLangInnerName = "zhoCN";
}
29 changes: 25 additions & 4 deletions SMT.Core/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ public static ExportResult Export(string rootPath, string dbPath, bool keepAsTex
return result;
}

public static bool Translate(string rootPath, string dbPath, string translateFileName, bool keepText)
public static bool Translate(string rootPath, string dbPath,
string translateFileName,
bool keepText,
bool multiLang,
bool useTrand
)
{
Logger.Info($"开始生成目标语言文件");
Logger.Info($"msg根目录:{rootPath}");
Logger.Info($"数据库路径:{dbPath}");
Logger.Info($"翻译文件路径:{translateFileName}");
Logger.Info($"保持原始文本不分割:{keepText}");
Logger.Info($"导出为繁体:{useTrand}");
// Logger.Info($"保持原始文本不分割:{keepText}");
Logger.Info($"双语模式:{multiLang}");
var langFile = new LangFile();
var db = new DB();
if (!langFile.Load(Path.Combine(rootPath, Configuration.SrcLangPath)) || !db.Load(dbPath))
Expand Down Expand Up @@ -173,7 +180,14 @@ public static bool Translate(string rootPath, string dbPath, string translateFil
translateCache[textId].AddParagraphOrText(globalId, dest);
}));
Logger.Info($"共处理 {translateCache.Count} 段文本");

// if (useTrand)
// {
// Configuration.UpdateDestLang("zhocn", "zhoCN");
// }
// else
// {
// Configuration.UpdateDestLang("zhotw", "zhoTW");
// }
var zhocnPath = Path.Combine(rootPath, Configuration.DestLangPath);
foreach (var bnd in langFile.Bnds)
{
Expand All @@ -192,7 +206,14 @@ public static bool Translate(string rootPath, string dbPath, string translateFil
if (entry.Text == null) continue;
if (translateCache.TryGetValue(file.ID * LangFile.Mtid + entry.ID, out var dest))
{
entry.Text = dest.Collect();
if (multiLang)
{
entry.Text = dest.Collect() + "\n" + entry.Text;
}
else
{
entry.Text = dest.Collect();
}
}
else
{
Expand Down
13 changes: 0 additions & 13 deletions SMT.Core/doc.md

This file was deleted.

5 changes: 2 additions & 3 deletions SMT.WPF/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,15 @@
Grid.Column="1"
Margin="2">移除中文和英文之间的空格</CheckBox>

<CheckBox Name="ExportAsTranditional"
<CheckBox Name="ExportAsTranditionalCheckBox"
Grid.Row="2"
Grid.Column="1"
IsEnabled="False"
Margin="2">生成繁体语言文件</CheckBox>

<CheckBox Name="MultiLang"
<CheckBox Name="MultiLangCheckBox"
Grid.Row="3"
Grid.Column="1"
IsEnabled="False"
Margin="2">生成中英双语样式</CheckBox>
</Grid>
<!--<CheckBox Name="AutoSortCheckBox"
Expand Down
10 changes: 6 additions & 4 deletions SMT.WPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class MainWindow : AdonisWindow
{
private static readonly string DbPath = Path.Combine(Directory.GetCurrentDirectory(), "db");
private static readonly string GlossaryPath = Path.Combine(Directory.GetCurrentDirectory(), "glossaries");
private static readonly string SoftwareName = "魂游MOD翻译工具 v2.8";
private static readonly string SoftwareName = "魂游MOD翻译工具 v2.10";

private static MemoryTarget MemoryTarget = new MemoryTarget
{
Expand Down Expand Up @@ -217,10 +217,8 @@ private async void ExportBtn_onClick(object sender, RoutedEventArgs e)
ShowTaskResult(false, "", "数据库为空,请检查软件完整性");
return;
}

//导出未翻译文本
var res = await Task.Run(() => Translator.Export(modRootPath, dbPath, keepText));

if (!res.Success)
{
ShowTaskResult(false, "", "导出失败");
Expand Down Expand Up @@ -264,6 +262,9 @@ private async void GenerateBtn_onClick(object sender, RoutedEventArgs e)
var modRootPath = ModPathTextBox.Text;
var dbPath = Path.Combine(DbPath, DbList[DbComboBox.SelectedIndex]);
var keepText = DoNotSplitTextBox.IsChecked ?? false;
var multiLang = MultiLangCheckBox.IsChecked ?? false;
var useTrand = ExportAsTranditionalCheckBox.IsChecked ?? false;

if (modRootPath.Length == 0)
{
ShowTaskResult(false, "", "请先设置msg目录");
Expand All @@ -279,7 +280,8 @@ private async void GenerateBtn_onClick(object sender, RoutedEventArgs e)
var dialog = new OpenFileDialog();
dialog.Filter = "Excel 文件 (*.xlsx)|*.xlsx|文本文件 (*.txt)|*.txt";
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
var res = await Task.Run(() => Translator.Translate(modRootPath, dbPath, dialog.FileName, keepText));

var res = await Task.Run(() => Translator.Translate(modRootPath, dbPath, dialog.FileName, keepText, multiLang, useTrand));
ShowTaskResult(res, "生成成功", "生成失败");
}
//TOOLS
Expand Down
3 changes: 2 additions & 1 deletion SMT.WPF/SMT.WPF.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>icon.ico</ApplicationIcon>
<PublishRelease>true</PublishRelease>
<AssemblyName>SoulsModTranslator</AssemblyName>
</PropertyGroup>
<ItemGroup>
<Content Include="icon.ico" />
Expand Down
6 changes: 3 additions & 3 deletions SMT.WPF/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def zip_folder(folder_path, output_path, compression=zipfile.ZIP_DEFLATED):


code = 0
if os.system("dotnet publish /p:OutputType=WinExe") != 0:
if os.system("dotnet publish") != 0:
exit(-1)
copy_files = ["db/", "glossaries/", "changelog.md", "oo2core_6_win64.dll"]
copy_files = ["db/", "glossaries/", "../changelog.md", "oo2core_6_win64.dll"]
for file in copy_files:
os.system("cp -r {} {}".format(file, publish_path))
zip_folder(publish_path, "SoulsModTranslator.zip")
zip_folder(publish_path, "../SoulsModTranslator.zip")
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### v2.10

- 重构分词规则和匹配算法,优化导出的文本格式
- 支持双语输出

### v2.7

- 优化词汇表功能,添加无视大小写
Expand Down

0 comments on commit ef8efea

Please sign in to comment.