Skip to content

Commit

Permalink
feat: 本地化重命名页面
Browse files Browse the repository at this point in the history
  • Loading branch information
textGamex committed Nov 29, 2024
1 parent 3ff32ed commit 0dee417
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Moder.Core/ViewsModels/Menus/RenameFileControlViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI.Xaml.Controls;
using Moder.Language.Strings;

namespace Moder.Core.ViewsModels.Menus;

Expand All @@ -14,7 +15,7 @@ public sealed partial class RenameFileControlViewModel : ObservableObject
private string _newName = string.Empty;

[ObservableProperty]
private string _errorMessage = "无效的文件或文件夹名称";
private string _errorMessage = Resource.RenameFile_InvalidFileOrFolderName;

private readonly ContentDialog _dialog;
private readonly SystemFileItem _fileItem;
Expand All @@ -37,7 +38,8 @@ public RenameFileControlViewModel(ContentDialog dialog, SystemFileItem fileItem)
private bool IsValidValue()
{
var isValid = !string.IsNullOrWhiteSpace(NewName);
ErrorMessage = "无效的文件或文件夹名称";
ErrorMessage = Resource.RenameFile_InvalidFileOrFolderName;

if (isValid && NewName.Length != 0)
{
isValid = NewName[0] != ' ' && NewName[^1] != ' ';
Expand All @@ -52,12 +54,12 @@ private bool IsValidValue()
{
isValid = NewName.IndexOfAny(_invalidChars) == -1;
}
ErrorMessage = "文件或文件夹名称包含非法字符";
ErrorMessage = Resource.RenameFile_NameContainInvalidChar;
}
if (isValid && HasEqualsNameItem())
{
isValid = false;
ErrorMessage = $"此位置已存在同名文件或文件夹 {NewName}, 请重新命名";
ErrorMessage = string.Format(Resource.RenameFile_NameAlreadyExists, NewName);
}
return isValid;
}
Expand Down
27 changes: 27 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.

9 changes: 9 additions & 0 deletions Moder.Language/Strings/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,13 @@
<data name="CharacterEditor.ParserErrorInfo" xml:space="preserve">
<value>解析 '{0}' 文件失败, 错误原因: {1}, 行数: {2}, 列数: {3}</value>
</data>
<data name="RenameFile.InvalidFileOrFolderName" xml:space="preserve">
<value>无效的文件或文件夹名称</value>
</data>
<data name="RenameFile.NameContainInvalidChar" xml:space="preserve">
<value>文件或文件夹名称包含非法字符</value>
</data>
<data name="RenameFile.NameAlreadyExists" xml:space="preserve">
<value>此位置已存在同名文件或文件夹 {0}, 请重新命名</value>
</data>
</root>

0 comments on commit 0dee417

Please sign in to comment.