From af2ba226ad56ab51691339dd00f740a40c07d5b1 Mon Sep 17 00:00:00 2001 From: Remo Date: Fri, 23 Aug 2024 08:51:23 +0200 Subject: [PATCH 1/5] use datacolumn caption if set --- Terminal.Gui/Views/TableView/DataTableSource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/TableView/DataTableSource.cs b/Terminal.Gui/Views/TableView/DataTableSource.cs index 02edeb8a34..3e543e90be 100644 --- a/Terminal.Gui/Views/TableView/DataTableSource.cs +++ b/Terminal.Gui/Views/TableView/DataTableSource.cs @@ -25,5 +25,5 @@ public class DataTableSource : ITableSource public int Columns => DataTable.Columns.Count; /// - public string [] ColumnNames => DataTable.Columns.Cast ().Select (c => c.ColumnName).ToArray (); + public string [] ColumnNames => DataTable.Columns.Cast ().Select (c => c.Caption ?? c.ColumnName).ToArray (); } From 524fab1987a775a15759ccad4e03395747896076 Mon Sep 17 00:00:00 2001 From: BDisp Date: Mon, 26 Aug 2024 14:06:11 +0100 Subject: [PATCH 2/5] Fixes #3693. HistoryTextItem derived from EventArgs doesn't follow the name rule convention. --- ...TextItem.cs => HistoryTextItemEventArgs.cs} | 8 ++++---- Terminal.Gui/Views/TextField.cs | 4 ++-- Terminal.Gui/Views/TextView.cs | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) rename Terminal.Gui/Views/{HistoryTextItem.cs => HistoryTextItemEventArgs.cs} (73%) diff --git a/Terminal.Gui/Views/HistoryTextItem.cs b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs similarity index 73% rename from Terminal.Gui/Views/HistoryTextItem.cs rename to Terminal.Gui/Views/HistoryTextItemEventArgs.cs index 9fab52134b..ca2ad3ad7e 100644 --- a/Terminal.Gui/Views/HistoryTextItem.cs +++ b/Terminal.Gui/Views/HistoryTextItemEventArgs.cs @@ -4,23 +4,23 @@ namespace Terminal.Gui; internal partial class HistoryText { - public class HistoryTextItem : EventArgs + public class HistoryTextItemEventArgs : EventArgs { public Point CursorPosition; public Point FinalCursorPosition; public bool IsUndoing; public List> Lines; public LineStatus LineStatus; - public HistoryTextItem RemovedOnAdded; + public HistoryTextItemEventArgs RemovedOnAdded; - public HistoryTextItem (List> lines, Point curPos, LineStatus linesStatus) + public HistoryTextItemEventArgs (List> lines, Point curPos, LineStatus linesStatus) { Lines = lines; CursorPosition = curPos; LineStatus = linesStatus; } - public HistoryTextItem (HistoryTextItem historyTextItem) + public HistoryTextItemEventArgs (HistoryTextItemEventArgs historyTextItem) { Lines = new List> (historyTextItem.Lines); CursorPosition = new Point (historyTextItem.CursorPosition.X, historyTextItem.CursorPosition.Y); diff --git a/Terminal.Gui/Views/TextField.cs b/Terminal.Gui/Views/TextField.cs index 9e4658e571..464451cb3b 100644 --- a/Terminal.Gui/Views/TextField.cs +++ b/Terminal.Gui/Views/TextField.cs @@ -585,7 +585,7 @@ public void ClearAllSelection () SetNeedsDisplay (); } - /// Allows clearing the items updating the original text. + /// Allows clearing the items updating the original text. public void ClearHistoryChanges () { _historyText.Clear (Text); } /// Copy the selected text to the clipboard. @@ -1382,7 +1382,7 @@ private Attribute GetReadOnlyColor () return new Attribute (cs.Disabled.Foreground, cs.Focus.Background); } - private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItem obj) + private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemEventArgs obj) { if (obj is null) { diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 988df51abc..93c25b0f0b 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -1269,7 +1269,7 @@ public enum LineStatus Added } - private readonly List _historyTextItems = new (); + private readonly List _historyTextItems = new (); private int _idxHistoryText = -1; private string? _originalText; public bool HasHistoryChanges => _idxHistoryText > -1; @@ -1304,7 +1304,7 @@ public void Add (List> lines, Point curPos, LineStatus lineStatus _idxHistoryText++; } - public event EventHandler? ChangeText; + public event EventHandler? ChangeText; public void Clear (string text) { @@ -1324,7 +1324,7 @@ public void Redo () _idxHistoryText++; - var historyTextItem = new HistoryTextItem (_historyTextItems [_idxHistoryText]) { IsUndoing = false }; + var historyTextItem = new HistoryTextItemEventArgs (_historyTextItems [_idxHistoryText]) { IsUndoing = false }; ProcessChanges (ref historyTextItem); @@ -1334,7 +1334,7 @@ public void Redo () public void ReplaceLast (List> lines, Point curPos, LineStatus lineStatus) { - HistoryTextItem? found = _historyTextItems.FindLast (x => x.LineStatus == lineStatus); + HistoryTextItemEventArgs? found = _historyTextItems.FindLast (x => x.LineStatus == lineStatus); if (found is { }) { @@ -1351,7 +1351,7 @@ public void Undo () _idxHistoryText--; - var historyTextItem = new HistoryTextItem (_historyTextItems [_idxHistoryText]) { IsUndoing = true }; + var historyTextItem = new HistoryTextItemEventArgs (_historyTextItems [_idxHistoryText]) { IsUndoing = true }; ProcessChanges (ref historyTextItem); @@ -1359,9 +1359,9 @@ public void Undo () } } - private void OnChangeText (HistoryTextItem? lines) { ChangeText?.Invoke (this, lines!); } + private void OnChangeText (HistoryTextItemEventArgs? lines) { ChangeText?.Invoke (this, lines!); } - private void ProcessChanges (ref HistoryTextItem historyTextItem) + private void ProcessChanges (ref HistoryTextItemEventArgs historyTextItem) { if (historyTextItem.IsUndoing) { @@ -2859,7 +2859,7 @@ public bool WordWrap } - /// Allows clearing the items updating the original text. + /// Allows clearing the items updating the original text. public void ClearHistoryChanges () { _historyText?.Clear (Text); } /// Closes the contents of the stream into the . @@ -4655,7 +4655,7 @@ private string GetSelectedRegion () return new ValueTuple (line, col); } - private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItem obj) + private void HistoryText_ChangeText (object sender, HistoryText.HistoryTextItemEventArgs obj) { SetWrapModel (); From b122744c60d77cc7d75aa6f9389357f364e40173 Mon Sep 17 00:00:00 2001 From: Remo Date: Tue, 27 Aug 2024 06:39:52 +0200 Subject: [PATCH 3/5] test datacolumn caption handling --- .../Views/TableView/DataTableSource.cs | 2 +- UnitTests/Views/TableViewTests.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/TableView/DataTableSource.cs b/Terminal.Gui/Views/TableView/DataTableSource.cs index 3e543e90be..a475e46b74 100644 --- a/Terminal.Gui/Views/TableView/DataTableSource.cs +++ b/Terminal.Gui/Views/TableView/DataTableSource.cs @@ -25,5 +25,5 @@ public class DataTableSource : ITableSource public int Columns => DataTable.Columns.Count; /// - public string [] ColumnNames => DataTable.Columns.Cast ().Select (c => c.Caption ?? c.ColumnName).ToArray (); + public string [] ColumnNames => DataTable.Columns.Cast ().Select (c => c.Caption).ToArray (); } diff --git a/UnitTests/Views/TableViewTests.cs b/UnitTests/Views/TableViewTests.cs index 61deab69c8..3f4a4bfed2 100644 --- a/UnitTests/Views/TableViewTests.cs +++ b/UnitTests/Views/TableViewTests.cs @@ -3169,6 +3169,29 @@ public void TestToggleCells_MultiSelectOn_Two_SquareSelects_BothToggled () Assert.Equal (8, tableView.GetAllSelectedCells ().Count ()); } + [Fact] + public void TestDataColumnCaption() + { + var tableView = new TableView (); + + var dt = new DataTable (); + dt.Columns.Add (new DataColumn () + { + Caption = "Caption 1", + ColumnName = "Column Name 1" + }); + dt.Columns.Add (new DataColumn () + { + ColumnName = "Column Name 2" + }); + + var dts = new DataTableSource (dt); + var cn = dts.ColumnNames; + + Assert.Equal ("Caption 1", cn [0]); + Assert.Equal ("Column Name 2", cn [1]); + } + private TableView GetABCDEFTableView (out DataTable dt) { var tableView = new TableView (); From 1540714951f218ca3d45b2c24e9ad9c1223e0613 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Aug 2024 20:48:52 +0100 Subject: [PATCH 4/5] Fixes #3698. ResourceManager GetResourceSet doesn't fallback to default for no translated keys. --- Terminal.Gui/Drawing/ColorStrings.cs | 24 +-- Terminal.Gui/Resources/GlobalResources.cs | 70 ++++++++ .../Resources/ResourceManagerWrapper.cs | 112 ++++++++++++ UnitTests/Resources/ResourceManagerTests.cs | 165 ++++++++++++++++++ 4 files changed, 360 insertions(+), 11 deletions(-) create mode 100644 Terminal.Gui/Resources/GlobalResources.cs create mode 100644 Terminal.Gui/Resources/ResourceManagerWrapper.cs create mode 100644 UnitTests/Resources/ResourceManagerTests.cs diff --git a/Terminal.Gui/Drawing/ColorStrings.cs b/Terminal.Gui/Drawing/ColorStrings.cs index b7f080042d..93899a6f51 100644 --- a/Terminal.Gui/Drawing/ColorStrings.cs +++ b/Terminal.Gui/Drawing/ColorStrings.cs @@ -11,8 +11,6 @@ namespace Terminal.Gui; /// public static class ColorStrings { - private static readonly ResourceManager _resourceManager = new (typeof (Strings)); - /// /// Gets the W3C standard string for . /// @@ -21,7 +19,7 @@ public static class ColorStrings public static string? GetW3CColorName (Color color) { // Fetch the color name from the resource file - return _resourceManager.GetString ($"#{color.R:X2}{color.G:X2}{color.B:X2}", CultureInfo.CurrentUICulture); + return GlobalResources.GetString ($"#{color.R:X2}{color.G:X2}{color.B:X2}", CultureInfo.CurrentUICulture); } /// @@ -30,14 +28,18 @@ public static class ColorStrings /// public static IEnumerable GetW3CColorNames () { - foreach (DictionaryEntry entry in _resourceManager.GetResourceSet (CultureInfo.CurrentUICulture, true, true)!) - { - string keyName = entry.Key.ToString () ?? string.Empty; + foreach (DictionaryEntry entry in GlobalResources.GetResourceSet ( + CultureInfo.CurrentUICulture, + true, + true, + e => + { + string keyName = e.Key.ToString () ?? string.Empty; - if (entry.Value is string colorName && keyName.StartsWith ('#')) - { - yield return colorName; - } + return e.Value is string && keyName.StartsWith ('#'); + })!) + { + yield return (entry.Value as string)!; } } @@ -50,7 +52,7 @@ public static IEnumerable GetW3CColorNames () public static bool TryParseW3CColorName (string name, out Color color) { // Iterate through all resource entries to find the matching color name - foreach (DictionaryEntry entry in _resourceManager.GetResourceSet (CultureInfo.CurrentUICulture, true, true)!) + foreach (DictionaryEntry entry in GlobalResources.GetResourceSet (CultureInfo.CurrentUICulture, true, true)!) { if (entry.Value is string colorName && colorName.Equals (name, StringComparison.OrdinalIgnoreCase)) { diff --git a/Terminal.Gui/Resources/GlobalResources.cs b/Terminal.Gui/Resources/GlobalResources.cs new file mode 100644 index 0000000000..b60836d9ac --- /dev/null +++ b/Terminal.Gui/Resources/GlobalResources.cs @@ -0,0 +1,70 @@ +#nullable enable + +using System.Collections; +using System.Globalization; +using System.Resources; + +namespace Terminal.Gui.Resources; + +/// +/// Provide static access to the ResourceManagerWrapper +/// +public static class GlobalResources +{ + private static readonly ResourceManagerWrapper _resourceManagerWrapper; + + static GlobalResources () + { + // Initialize the ResourceManagerWrapper once + var resourceManager = new ResourceManager (typeof (Strings)); + _resourceManagerWrapper = new (resourceManager); + } + + /// + /// Looks up a resource value for a particular name. Looks in the specified CultureInfo, and if not found, all parent + /// CultureInfos. + /// + /// + /// + /// Null if the resource was not found in the current culture or the invariant culture. + public static object GetObject (string name, CultureInfo culture = null!) { return _resourceManagerWrapper.GetObject (name, culture); } + + /// + /// Looks up a set of resources for a particular CultureInfo. This is not useful for most users of the ResourceManager + /// - call GetString() or GetObject() instead. The parameters let you control whether the ResourceSet is created if it + /// hasn't yet been loaded and if parent CultureInfos should be loaded as well for resource inheritance. + /// + /// + /// + /// + /// + public static ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents) + { + return _resourceManagerWrapper.GetResourceSet (culture, createIfNotExists, tryParents)!; + } + + /// + /// Looks up a set of resources for a particular CultureInfo. This is not useful for most users of the ResourceManager + /// - call GetString() or GetObject() instead. The parameters let you control whether the ResourceSet is created if it + /// hasn't yet been loaded and if parent CultureInfos should be loaded as well for resource inheritance. Allows + /// filtering of resources. + /// + /// + /// + /// + /// + /// + public static ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents, Func? filter) + { + return _resourceManagerWrapper.GetResourceSet (culture, createIfNotExists, tryParents, filter)!; + } + + /// + /// Looks up a resource value for a particular name. Looks in the specified CultureInfo, and if not found, all parent + /// CultureInfos. + /// + /// + /// + /// Null if the resource was not found in the current culture or the invariant culture. + public static string GetString (string name, CultureInfo? culture = null!) { return _resourceManagerWrapper.GetString (name, culture); } +} diff --git a/Terminal.Gui/Resources/ResourceManagerWrapper.cs b/Terminal.Gui/Resources/ResourceManagerWrapper.cs new file mode 100644 index 0000000000..ff4eeeb35d --- /dev/null +++ b/Terminal.Gui/Resources/ResourceManagerWrapper.cs @@ -0,0 +1,112 @@ +#nullable enable + +using System.Collections; +using System.Globalization; +using System.Resources; + +namespace Terminal.Gui.Resources; + +internal class ResourceManagerWrapper (ResourceManager resourceManager) +{ + private readonly ResourceManager _resourceManager = resourceManager ?? throw new ArgumentNullException (nameof (resourceManager)); + + // Optionally, expose other ResourceManager methods as needed + public object GetObject (string name, CultureInfo culture = null!) + { + object value = _resourceManager.GetObject (name, culture)!; + + if (Equals (culture, CultureInfo.InvariantCulture)) + { + return value; + } + + if (value is null) + { + value = _resourceManager.GetObject (name, CultureInfo.InvariantCulture)!; + } + + return value; + } + + public ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents) + { + ResourceSet value = _resourceManager.GetResourceSet (culture, createIfNotExists, tryParents)!; + + if (Equals (culture, CultureInfo.InvariantCulture)) + { + return value; + } + + if (value!.Cast ().Any ()) + { + value = _resourceManager.GetResourceSet (CultureInfo.InvariantCulture, createIfNotExists, tryParents)!; + } + + return value; + } + + public ResourceSet? GetResourceSet (CultureInfo culture, bool createIfNotExists, bool tryParents, Func? filter) + { + ResourceSet value = _resourceManager.GetResourceSet (culture, createIfNotExists, tryParents)!; + + IEnumerable filteredEntries = value.Cast ().Where (filter ?? (_ => true)); + + ResourceSet? filteredValue = ConvertToResourceSet (filteredEntries); + + if (Equals (culture, CultureInfo.InvariantCulture)) + { + return filteredValue; + } + + if (!filteredValue!.Cast ().Any ()) + { + filteredValue = GetResourceSet (CultureInfo.InvariantCulture, createIfNotExists, tryParents, filter)!; + } + + return filteredValue; + } + + public string GetString (string name, CultureInfo? culture = null!) + { + // Attempt to get the string for the specified culture + string value = _resourceManager.GetString (name, culture)!; + + // If it's already using the invariant culture return + if (Equals (culture, CultureInfo.InvariantCulture)) + { + return value; + } + + // If the string is empty or null, fall back to the invariant culture + if (string.IsNullOrEmpty (value)) + { + value = _resourceManager.GetString (name, CultureInfo.InvariantCulture)!; + } + + return value; + } + + private static ResourceSet? ConvertToResourceSet (IEnumerable entries) + { + using var memoryStream = new MemoryStream (); + + using var resourceWriter = new ResourceWriter (memoryStream); + + // Add each DictionaryEntry to the ResourceWriter + foreach (DictionaryEntry entry in entries) + { + resourceWriter.AddResource ((string)entry.Key, entry.Value); + } + + // Finish writing to the stream + resourceWriter.Generate (); + + // Reset the stream position to the beginning + memoryStream.Position = 0; + + // Create a ResourceSet from the MemoryStream + var resourceSet = new ResourceSet (memoryStream); + + return resourceSet; + } +} diff --git a/UnitTests/Resources/ResourceManagerTests.cs b/UnitTests/Resources/ResourceManagerTests.cs new file mode 100644 index 0000000000..cd1488fd6a --- /dev/null +++ b/UnitTests/Resources/ResourceManagerTests.cs @@ -0,0 +1,165 @@ +#nullable enable + +using System.Collections; +using System.Globalization; +using System.Resources; +using Terminal.Gui.Resources; + +namespace Terminal.Gui.ResourcesTests; + +public class ResourceManagerTests +{ + private const string DODGER_BLUE_COLOR_KEY = "#1E90FF"; + private const string DODGER_BLUE_COLOR_NAME = "DodgerBlue"; + private const string EXISTENT_CULTURE = "pt-PT"; + private const string NO_EXISTENT_CULTURE = "de-DE"; + private const string NO_EXISTENT_KEY = "blabla"; + private const string NO_TRANSLATED_KEY = "fdDeleteTitle"; + private const string NO_TRANSLATED_VALUE = "Delete {0}"; + private const string TRANSLATED_KEY = "ctxSelectAll"; + private const string TRANSLATED_VALUE = "_Selecionar Tudo"; + private static readonly string _stringsNoTranslatedKey = Strings.fdDeleteTitle; + private static readonly string _stringsTranslatedKey = Strings.ctxSelectAll; + private static readonly CultureInfo _savedCulture = CultureInfo.CurrentCulture; + private static readonly CultureInfo _savedUICulture = CultureInfo.CurrentUICulture; + + [Fact] + public void GetObject_Does_Not_Overflows_If_Key_Does_Not_Exist () { Assert.Null (GlobalResources.GetObject (NO_EXISTENT_KEY, CultureInfo.CurrentCulture)); } + + [Fact] + public void GetObject_FallBack_To_Default_For_No_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE); + + Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetObject (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture)); + + RestoreCurrentCultures (); + } + + [Fact] + public void GetObject_FallBack_To_Default_For_Not_Translated_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE); + + Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetObject (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture)); + + RestoreCurrentCultures (); + } + + [Fact] + public void GetResourceSet_FallBack_To_Default_For_No_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE); + + // W3CColors.GetColorNames also calls ColorStrings.GetW3CColorNames + string [] colorNames = new W3CColors ().GetColorNames ().ToArray (); + Assert.Contains (DODGER_BLUE_COLOR_NAME, colorNames); + Assert.DoesNotContain (NO_TRANSLATED_VALUE, colorNames); + + RestoreCurrentCultures (); + } + + [Fact] + public void GetResourceSet_FallBack_To_Default_For_Not_Translated_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (EXISTENT_CULTURE); + + // These aren't already translated + // ColorStrings.GetW3CColorNames method uses GetResourceSet method to retrieve color names + IEnumerable colorNames = ColorStrings.GetW3CColorNames (); + Assert.NotEmpty (colorNames); + + // W3CColors.GetColorNames also calls ColorStrings.GetW3CColorNames + colorNames = new W3CColors ().GetColorNames ().ToArray (); + Assert.Contains (DODGER_BLUE_COLOR_NAME, colorNames); + Assert.DoesNotContain (NO_TRANSLATED_VALUE, colorNames); + + // ColorStrings.TryParseW3CColorName method uses GetResourceSet method to retrieve a color value + Assert.True (ColorStrings.TryParseW3CColorName (DODGER_BLUE_COLOR_NAME, out Color color)); + Assert.Equal (DODGER_BLUE_COLOR_KEY, color.ToString ()); + + RestoreCurrentCultures (); + } + + [Fact] + public void GetResourceSet_With_Filter_Does_Not_Overflows_If_Key_Does_Not_Exist () + { + ResourceSet value = GlobalResources.GetResourceSet (CultureInfo.CurrentCulture, true, true, d => (string)d.Key == NO_EXISTENT_KEY)!; + Assert.NotNull (value); + Assert.Empty (value.Cast ()); + } + + [Fact] + public void GetResourceSet_Without_Filter_Does_Not_Overflows_If_Key_Does_Not_Exist () + { + ResourceSet value = GlobalResources.GetResourceSet (CultureInfo.CurrentCulture, true, true)!; + Assert.NotNull (value); + Assert.NotEmpty (value.Cast ()); + } + + [Fact] + public void GetString_Does_Not_Overflows_If_Key_Does_Not_Exist () { Assert.Null (GlobalResources.GetString (NO_EXISTENT_KEY, CultureInfo.CurrentCulture)); } + + [Fact] + public void GetString_FallBack_To_Default_For_No_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE); + + Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetString (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture)); + + RestoreCurrentCultures (); + } + + [Fact] + public void GetString_FallBack_To_Default_For_Not_Translated_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (EXISTENT_CULTURE); + + // This is really already translated + Assert.Equal (TRANSLATED_VALUE, GlobalResources.GetString (TRANSLATED_KEY, CultureInfo.CurrentCulture)); + + // These aren't already translated + // Calling Strings.fdDeleteBody return always the invariant culture + Assert.Equal (NO_TRANSLATED_VALUE, GlobalResources.GetString (NO_TRANSLATED_KEY, CultureInfo.CurrentCulture)); + + RestoreCurrentCultures (); + } + + [Fact] + public void Strings_Always_FallBack_To_Default_For_No_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (NO_EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (NO_EXISTENT_CULTURE); + + Assert.Equal (NO_TRANSLATED_VALUE, _stringsNoTranslatedKey); + + RestoreCurrentCultures (); + } + + [Fact] + public void Strings_Always_FallBack_To_Default_For_Not_Translated_Existent_Culture_File () + { + CultureInfo.CurrentCulture = new (EXISTENT_CULTURE); + CultureInfo.CurrentUICulture = new (EXISTENT_CULTURE); + + // This is really already translated + Assert.Equal (TRANSLATED_VALUE, _stringsTranslatedKey); + + // This isn't already translated + Assert.Equal (NO_TRANSLATED_VALUE, _stringsNoTranslatedKey); + + RestoreCurrentCultures (); + } + + private void RestoreCurrentCultures () + { + CultureInfo.CurrentCulture = _savedCulture; + CultureInfo.CurrentUICulture = _savedUICulture; + } +} From c1e3ece8a3bdaa2683fb21455a80d8b36abc4bb5 Mon Sep 17 00:00:00 2001 From: BDisp Date: Tue, 27 Aug 2024 23:29:51 +0100 Subject: [PATCH 5/5] Code cleanup. --- Terminal.Gui/Drawing/ColorStrings.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Terminal.Gui/Drawing/ColorStrings.cs b/Terminal.Gui/Drawing/ColorStrings.cs index 93899a6f51..a6b90d8002 100644 --- a/Terminal.Gui/Drawing/ColorStrings.cs +++ b/Terminal.Gui/Drawing/ColorStrings.cs @@ -1,7 +1,6 @@ #nullable enable using System.Collections; using System.Globalization; -using System.Resources; using Terminal.Gui.Resources; namespace Terminal.Gui;