Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18: 添加本地化文本 #44

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions Moder.Core/Models/SystemFileItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private async Task RenameAsync()
{
Title = Resource.Common_Rename,
PrimaryButtonText = Resource.Common_Ok,
CloseButtonText = Resource.Common_Cancel
CloseButtonText = Resource.Common_Cancel,
};

var view = new RenameFileControlView(dialog, this);
Expand All @@ -104,7 +104,7 @@ private async Task RenameAsync()
var result = await dialog.ShowAsync();
if (result != ContentDialogResult.Primary)
{
Log.Debug("取消重命名");
Log.Debug(Resource.RenameFile_CancelRename);
return;
}

Expand All @@ -116,14 +116,14 @@ private async Task RenameAsync()
var parentDir = Path.GetDirectoryName(FullPath);
if (parentDir is null)
{
Log.Warn("重命名文件失败,无法获取路径:{FullPath}", FullPath);
Log.Warn($"{Resource.RenameFile_CannotAquirePath}{FullPath}");
return;
}

var newPath = Path.Combine(parentDir, view.NewName);
if (Path.Exists(newPath))
{
Log.Warn("重命名失败,目标文件或文件夹已存在:{FullPath}", FullPath);
Log.Warn($"{Resource.RenameFile_TargetAlreadyExists}{FullPath}");
return;
}

Expand All @@ -133,8 +133,8 @@ private async Task RenameAsync()
}
catch (Exception e)
{
Log.Error(e, "重命名文件或文件夹时发生错误");
await MessageBoxService.ErrorAsync("重命名文件或文件夹时发生错误");
Log.Error(e, Resource.RenameFile_ErrorOccurs);
await MessageBoxService.ErrorAsync(Resource.RenameFile_ErrorOccurs);
}
}

Expand All @@ -153,8 +153,10 @@ private void Rename(string newPath)
[RelayCommand]
private async Task DeleteFile()
{
var text = IsFile ? $"确认删除 '{Name}' 吗?" : $"确认删除 '{Name}' 及其内容吗?";
text += "\n\n您可以从回收站还原此文件";
var text = IsFile
? string.Format(Resource.DeleteFile_EnsureFile, Name)
: string.Format(Resource.DeleteFile_EnsureFolder, Name);
text += $"\n\n{Resource.DeleteFile_CanFindBack}";
var dialog = MessageBoxManager.GetMessageBoxStandard(Resource.Common_Delete, text, ButtonEnum.YesNo);

var result = await dialog.ShowAsync();
Expand All @@ -166,13 +168,8 @@ private async Task DeleteFile()
}
else
{
await MessageBoxService.ErrorAsync($"删除失败, 原因: {errorMessage}");
Log.Warn(
"删除文件或文件夹失败:{FullPath}, 错误信息: {ErrorMessage} 错误代码: {Code}",
FullPath,
errorMessage,
errorCode
);
await MessageBoxService.ErrorAsync($"{Resource.DeleteFile_Failed}{errorMessage}");
Log.Warn(string.Format(Resource.DeleteFile_FailedLog, FullPath, errorMessage, errorCode));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Versioning;
using Moder.Language.Strings;
using NLog;
using Vanara.PInvoke;
using Vanara.Windows.Shell;
Expand All @@ -25,7 +26,7 @@ out int errorCode

if (!Path.Exists(fileOrDirectoryPath))
{
errorMessage = "文件或文件夹不存在";
errorMessage = Resource.FileManager_NotExist;
errorCode = 0;
return false;
}
Expand Down Expand Up @@ -69,7 +70,7 @@ public bool TryShowInExplorer(
}
catch (Exception e)
{
Log.Error(e, "在文件资源管理器中打开失败, path:{Path}", fileOrDirectoryPath);
Log.Error(e, $"{Resource.FileManager_OpenFailed}{fileOrDirectoryPath}");
errorMessage = e.Message;
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions Moder.Core/ViewsModel/Menus/AppInitializeControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MessageBoxService messageBox
[RelayCommand]
private async Task SelectGameRootFolder()
{
var gameRootPath = await SelectFolderInteraction.HandleAsync("选择游戏根目录");
var gameRootPath = await SelectFolderInteraction.HandleAsync(Resource.InitializePage_SelectGameRootPath);
if (string.IsNullOrEmpty(gameRootPath))
{
return;
Expand All @@ -49,7 +49,7 @@ private async Task SelectGameRootFolder()
[RelayCommand]
private async Task SelectModRootFolder()
{
var modRootPath = await SelectFolderInteraction.HandleAsync("选择Mod根目录");
var modRootPath = await SelectFolderInteraction.HandleAsync(Resource.InitializePage_SelectModRootPath);
if (string.IsNullOrEmpty(modRootPath))
{
return;
Expand All @@ -70,7 +70,7 @@ private async Task Submit()

settingService.GameRootFolderPath = GameRootFolderPath;
settingService.ModRootFolderPath = ModRootFolderPath;
Log.Info("资源目录设置成功");
Log.Info(Resource.InitializePage_SetResourceDirectorySuccess);

WeakReferenceMessenger.Default.Send(new CompleteAppInitializeMessage());
}
Expand Down
108 changes: 108 additions & 0 deletions Moder.Language/Strings/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Moder.Language/Strings/Resource.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,47 @@
</data>
<data name="Common.Complete" xml:space="preserve">
<value>Complete</value>
</data>
<data name="InitializePage.SelectGameRootPath" xml:space="preserve">
<value>Select Game Root Path</value>
</data>
<data name="InitializePage.SelectModRootPath" xml:space="preserve">
<value>Select Mod Root Path</value>
</data>
<data name="RenameFile.CancelRename" xml:space="preserve">
<value>Cencel Rename</value>
</data>
<data name="RenameFile.CannotAquirePath" xml:space="preserve">
<value>Rename failed, cannot aquire path: </value>
</data>
<data name="RenameFile.TargetAlreadyExists" xml:space="preserve">
<value>Rename failed, target file or folder already exists: </value>
</data>
<data name="RenameFile_ErrorOccurs" xml:space="preserve">
<value>An error occurs within file or folder renaming</value>
</data>
<data name="DeleteFile_EnsureFile" xml:space="preserve">
<value>Are you sure to delete '{0}'?</value>
</data>
<data name="DeleteFile_EnsureFolder" xml:space="preserve">
<value>Are you sure to delete '{0}' and all of its content?</value>
</data>
<data name="DeleteFile_CanFindBack" xml:space="preserve">
<value>You can restore from recycle bin</value>
</data>
<data name="DeleteFile.Failed" xml:space="preserve">
<value>Delete failed because: </value>
</data>
<data name="DeleteFile_FailedLog" xml:space="preserve">
<value>Delete file or folder failed: {0}. Error message: {1}. Error code: {2}</value>
</data>
<data name="FileManager.NotExist" xml:space="preserve">
<value>File or folder doesn't exist</value>
</data>
<data name="FileManager.OpenFailed" xml:space="preserve">
<value>Open failed in the file manager: {0}</value>
</data>
<data name="InitializePage.SetResourceDirectorySuccess" xml:space="preserve">
<value>Resource directory sets successful</value>
</data>
</root>
36 changes: 36 additions & 0 deletions Moder.Language/Strings/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,40 @@
<data name="Common.Complete" xml:space="preserve">
<value>完成</value>
</data>
<data name="RenameFile.CancelRename" xml:space="preserve">
<value>取消重命名</value>
</data>
<data name="RenameFile.CannotAquirePath" xml:space="preserve">
<value>重命名失败,无法获取路径:</value>
</data>
<data name="RenameFile.TargetAlreadyExists" xml:space="preserve">
<value>重命名失败,目标文件或文件夹已存在:</value>
</data>
<data name="RenameFile_ErrorOccurs" xml:space="preserve">
<value>重命名文件或文件夹时发生错误</value>
</data>
<data name="DeleteFile_EnsureFile" xml:space="preserve">
<value>确认删除 '{0}' 吗?</value>
</data>
<data name="DeleteFile_EnsureFolder" xml:space="preserve">
<value>确认删除 '{0}' 及其内容吗?</value>
</data>
<data name="DeleteFile_CanFindBack" xml:space="preserve">
<value>您可以从回收站还原此文件</value>
</data>
<data name="DeleteFile.Failed" xml:space="preserve">
<value>删除失败,原因:</value>
</data>
<data name="DeleteFile_FailedLog" xml:space="preserve">
<value>删除文件或文件夹失败:{0}, 错误信息: {1} 错误代码: {2}</value>
</data>
<data name="FileManager.NotExist" xml:space="preserve">
<value>文件或文件夹不存在</value>
</data>
<data name="FileManager.OpenFailed" xml:space="preserve">
<value>在文件资源管理器中打开失败:{0}</value>
</data>
<data name="InitializePage.SetResourceDirectorySuccess" xml:space="preserve">
<value>资源目录设置成功</value>
</data>
</root>
Loading