From eaa2a4a44d23f742d7f56ad15442051b416662c5 Mon Sep 17 00:00:00 2001 From: RoxCian <40283094+RoxCian@users.noreply.github.com> Date: Thu, 28 Sep 2023 17:40:34 +0800 Subject: [PATCH] Update localizations for FileDialog. - Separate some of localization resource keys for cases of hotkeyed string: - `fdOpen` -> `fdOpen` and `btnOpen` - `fdSave` -> `fdSave` and `btnSave` - `fdSaveAs` -> `fdSaveAs` and `btnSaveAs` - Modify or add resource keys for general purpose: - `fdNo` -> `btnNo` - `fdYes` -> `btnYes` - +`btnCancel` - +`btnOk` - Extract the procedure of build default title to `GetDefaultTitle ()` for FileDialog. --- .../FileServices/DefaultFileOperations.cs | 8 +- Terminal.Gui/Resources/Strings.Designer.cs | 81 ++++++++++++++----- Terminal.Gui/Resources/Strings.fr-FR.resx | 11 ++- Terminal.Gui/Resources/Strings.ja-JP.resx | 23 +++++- Terminal.Gui/Resources/Strings.pt-PT.resx | 9 +++ Terminal.Gui/Resources/Strings.resx | 19 ++++- Terminal.Gui/Resources/Strings.zh-Hans.resx | 23 +++++- Terminal.Gui/Views/FileDialog.cs | 36 ++++++--- Terminal.Gui/Views/OpenDialog.cs | 7 +- Terminal.Gui/Views/SaveDialog.cs | 21 ++++- 10 files changed, 188 insertions(+), 50 deletions(-) diff --git a/Terminal.Gui/FileServices/DefaultFileOperations.cs b/Terminal.Gui/FileServices/DefaultFileOperations.cs index b2512cea6..c626dfaec 100644 --- a/Terminal.Gui/FileServices/DefaultFileOperations.cs +++ b/Terminal.Gui/FileServices/DefaultFileOperations.cs @@ -24,7 +24,7 @@ namespace Terminal.Gui { int result = MessageBox.Query ( string.Format (Strings.fdDeleteTitle, adjective), string.Format (Strings.fdDeleteBody, adjective), - Strings.fdYes, Strings.fdNo); + Strings.btnYes, Strings.btnNo); try { if (result == 0) { @@ -37,7 +37,7 @@ namespace Terminal.Gui { return true; } } catch (Exception ex) { - MessageBox.ErrorQuery (Strings.fdDeleteFailedTitle, ex.Message, "Ok"); + MessageBox.ErrorQuery (Strings.fdDeleteFailedTitle, ex.Message, Strings.btnOk); } return false; @@ -47,14 +47,14 @@ namespace Terminal.Gui { { bool confirm = false; - var btnOk = new Button ("Ok") { + var btnOk = new Button (Strings.btnOk) { IsDefault = true, }; btnOk.Clicked += (s, e) => { confirm = true; Application.RequestStop (); }; - var btnCancel = new Button ("Cancel"); + var btnCancel = new Button (Strings.btnCancel); btnCancel.Clicked += (s, e) => { confirm = false; Application.RequestStop (); diff --git a/Terminal.Gui/Resources/Strings.Designer.cs b/Terminal.Gui/Resources/Strings.Designer.cs index 00d978a76..a71f357ce 100644 --- a/Terminal.Gui/Resources/Strings.Designer.cs +++ b/Terminal.Gui/Resources/Strings.Designer.cs @@ -60,6 +60,69 @@ namespace Terminal.Gui.Resources { } } + /// + /// Looks up a localized string similar to Cancel. + /// + internal static string btnCancel { + get { + return ResourceManager.GetString("btnCancel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No. + /// + internal static string btnNo { + get { + return ResourceManager.GetString("btnNo", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to OK. + /// + internal static string btnOk { + get { + return ResourceManager.GetString("btnOk", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Open. + /// + internal static string btnOpen { + get { + return ResourceManager.GetString("btnOpen", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save. + /// + internal static string btnSave { + get { + return ResourceManager.GetString("btnSave", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Save as. + /// + internal static string btnSaveAs { + get { + return ResourceManager.GetString("btnSaveAs", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Yes. + /// + internal static string btnYes { + get { + return ResourceManager.GetString("btnYes", resourceCulture); + } + } + /// /// Looks up a localized string similar to _Copy. /// @@ -267,15 +330,6 @@ namespace Terminal.Gui.Resources { } } - /// - /// Looks up a localized string similar to No. - /// - internal static string fdNo { - get { - return ResourceManager.GetString("fdNo", resourceCulture); - } - } - /// /// Looks up a localized string similar to Open. /// @@ -393,15 +447,6 @@ namespace Terminal.Gui.Resources { } } - /// - /// Looks up a localized string similar to Yes. - /// - internal static string fdYes { - get { - return ResourceManager.GetString("fdYes", resourceCulture); - } - } - /// /// Looks up a localized string similar to _Back. /// diff --git a/Terminal.Gui/Resources/Strings.fr-FR.resx b/Terminal.Gui/Resources/Strings.fr-FR.resx index 2c422f224..e6dcfcaea 100644 --- a/Terminal.Gui/Resources/Strings.fr-FR.resx +++ b/Terminal.Gui/Resources/Strings.fr-FR.resx @@ -148,7 +148,7 @@ Enregistrer - E_nregistrer sous + Enregistrer sous Ouvrir @@ -168,4 +168,13 @@ Prochai_n... + + Enregistrer + + + E_nregistrer sous + + + Ouvrir + \ No newline at end of file diff --git a/Terminal.Gui/Resources/Strings.ja-JP.resx b/Terminal.Gui/Resources/Strings.ja-JP.resx index a7b0e361a..35d0e2bf8 100644 --- a/Terminal.Gui/Resources/Strings.ja-JP.resx +++ b/Terminal.Gui/Resources/Strings.ja-JP.resx @@ -145,10 +145,10 @@ ファイル - 保存 (_S) + 保存 - 名前を付けて保存 (_S) + 名前を付けて保存 開く @@ -189,10 +189,10 @@ 新規ディレクトリ - + いいえ (_N) - + はい (_Y) @@ -240,4 +240,19 @@ 任意ファイル + + キャンセル (_C) + + + OK (_O) + + + 開く (_O) + + + 保存 (_S) + + + 名前を付けて保存 (_S) + \ No newline at end of file diff --git a/Terminal.Gui/Resources/Strings.pt-PT.resx b/Terminal.Gui/Resources/Strings.pt-PT.resx index a8385c556..bfd60ce15 100644 --- a/Terminal.Gui/Resources/Strings.pt-PT.resx +++ b/Terminal.Gui/Resources/Strings.pt-PT.resx @@ -168,4 +168,13 @@ S_eguir + + Guardar como + + + Guardar + + + Abrir + \ No newline at end of file diff --git a/Terminal.Gui/Resources/Strings.resx b/Terminal.Gui/Resources/Strings.resx index 873c6184d..887431f43 100644 --- a/Terminal.Gui/Resources/Strings.resx +++ b/Terminal.Gui/Resources/Strings.resx @@ -226,7 +226,7 @@ New Folder - + No @@ -238,10 +238,25 @@ Rename - + Yes Existing + + Open + + + Save + + + Save as + + + OK + + + Cancel + \ No newline at end of file diff --git a/Terminal.Gui/Resources/Strings.zh-Hans.resx b/Terminal.Gui/Resources/Strings.zh-Hans.resx index 347e475f1..b0358523f 100644 --- a/Terminal.Gui/Resources/Strings.zh-Hans.resx +++ b/Terminal.Gui/Resources/Strings.zh-Hans.resx @@ -145,10 +145,10 @@ 文件 - 保存 (_S) + 保存 - 另存为 (_S) + 另存为 打开 @@ -222,7 +222,7 @@ 新建文件夹 - + 否 (_N) @@ -234,10 +234,25 @@ 重命名 - + 是 (_Y) 已有 + + 确定 (_O) + + + 打开 (_O) + + + 保存 (_S) + + + 另存为 (_S) + + + 取消 (_C) + \ No newline at end of file diff --git a/Terminal.Gui/Views/FileDialog.cs b/Terminal.Gui/Views/FileDialog.cs index bf5b9adf2..e71fdf9c6 100644 --- a/Terminal.Gui/Views/FileDialog.cs +++ b/Terminal.Gui/Views/FileDialog.cs @@ -154,7 +154,7 @@ namespace Terminal.Gui { this.NavigateIf (k, Key.CursorUp, this.tableView); }; - this.btnCancel = new Button ("Cancel") { + this.btnCancel = new Button (Strings.btnCancel) { Y = Pos.AnchorEnd (1), X = Pos.Function (() => this.Bounds.Width @@ -710,20 +710,32 @@ namespace Terminal.Gui { this.tbPath.SelectAll (); if (string.IsNullOrEmpty (Title)) { - switch (OpenMode) { - case OpenMode.File: - this.Title = $"{Strings.fdOpen} {(MustExist ? Strings.fdExisting + " " : "")}{Strings.fdFile}"; - break; - case OpenMode.Directory: - this.Title = $"{Strings.fdOpen} {(MustExist ? Strings.fdExisting + " " : "")}{Strings.fdDirectory}"; - break; - case OpenMode.Mixed: - this.Title = $"{Strings.fdOpen} {(MustExist ? Strings.fdExisting : "")}"; - break; - } + this.Title = GetDefaultTitle (); } this.LayoutSubviews (); } + /// + /// Gets a default dialog title, when is not set or empty, + /// result of the function will be shown. + /// + protected virtual string GetDefaultTitle () + { + List titleParts = new () { + Strings.fdOpen + }; + if (MustExist) { + titleParts.Add (Strings.fdExisting); + } + switch (OpenMode) { + case OpenMode.File: + titleParts.Add (Strings.fdFile); + break; + case OpenMode.Directory: + titleParts.Add (Strings.fdDirectory); + break; + } + return string.Join (' ', titleParts); + } private void AllowedTypeMenuClicked (int idx) { diff --git a/Terminal.Gui/Views/OpenDialog.cs b/Terminal.Gui/Views/OpenDialog.cs index 4e16831fe..674a585ee 100644 --- a/Terminal.Gui/Views/OpenDialog.cs +++ b/Terminal.Gui/Views/OpenDialog.cs @@ -55,8 +55,7 @@ namespace Terminal.Gui { /// To select more than one file, users can use the spacebar, or control-t. /// /// - public class OpenDialog : FileDialog { - + public class OpenDialog : FileDialog { /// /// Initializes a new . /// @@ -70,9 +69,9 @@ namespace Terminal.Gui { /// The open mode. public OpenDialog (string title, List allowedTypes = null, OpenMode openMode = OpenMode.File) { - this.OpenMode = openMode; + OpenMode = openMode; Title = title; - Style.OkButtonText = openMode == OpenMode.File ? Strings.fdOpen : openMode == OpenMode.Directory ? Strings.fdSelectFolder : Strings.fdSelectMixed; + Style.OkButtonText = openMode == OpenMode.File ? Strings.btnOpen : openMode == OpenMode.Directory ? Strings.fdSelectFolder : Strings.fdSelectMixed; if (allowedTypes != null) { AllowedTypes = allowedTypes; diff --git a/Terminal.Gui/Views/SaveDialog.cs b/Terminal.Gui/Views/SaveDialog.cs index b5d689311..e357e704f 100644 --- a/Terminal.Gui/Views/SaveDialog.cs +++ b/Terminal.Gui/Views/SaveDialog.cs @@ -42,7 +42,7 @@ namespace Terminal.Gui { { //: base (title, prompt: Strings.fdSave, nameFieldLabel: $"{Strings.fdSaveAs}:", message: message, allowedTypes) { } Title = title; - Style.OkButtonText = Strings.fdSave; + Style.OkButtonText = Strings.btnSave; if(allowedTypes != null) { AllowedTypes = allowedTypes; @@ -62,5 +62,24 @@ namespace Terminal.Gui { return Path; } } + + protected override string GetDefaultTitle () + { + List titleParts = new () { + Strings.fdSave + }; + if (MustExist) { + titleParts.Add (Strings.fdExisting); + } + switch (OpenMode) { + case OpenMode.File: + titleParts.Add (Strings.fdFile); + break; + case OpenMode.Directory: + titleParts.Add (Strings.fdDirectory); + break; + } + return string.Join (' ', titleParts); + } } }