diff --git a/SelfContained/Program.cs b/SelfContained/Program.cs index b723bcbd4..f2f157670 100644 --- a/SelfContained/Program.cs +++ b/SelfContained/Program.cs @@ -1,6 +1,7 @@ // This is a simple example application for a self-contained single file. using System.Diagnostics.CodeAnalysis; +using System.Globalization; using Terminal.Gui; namespace SelfContained; @@ -10,7 +11,23 @@ public static class Program [RequiresUnreferencedCode ("Calls Terminal.Gui.Application.Run(Func, ConsoleDriver)")] private static void Main (string [] args) { - Application.Run ().Dispose (); + Application.Init (); + + if (Equals (Thread.CurrentThread.CurrentUICulture, CultureInfo.InvariantCulture)) + { + System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 0); + } + else + { + System.Diagnostics.Debug.Assert (Application.SupportedCultures.Count == 4); + System.Diagnostics.Debug.Assert (Equals (CultureInfo.CurrentCulture, Thread.CurrentThread.CurrentUICulture)); + } + + ExampleWindow app = new (); + Application.Run (app); + + // Dispose the app object before shutdown + app.Dispose (); // Before the application exits, reset Terminal.Gui for clean shutdown Application.Shutdown (); diff --git a/SelfContained/SelfContained.csproj b/SelfContained/SelfContained.csproj index b4ffbe030..af651e3ca 100644 --- a/SelfContained/SelfContained.csproj +++ b/SelfContained/SelfContained.csproj @@ -8,7 +8,7 @@ true Link true - true + false embedded diff --git a/Terminal.Gui/Application/Application.cs b/Terminal.Gui/Application/Application.cs index 477553263..225eb17f3 100644 --- a/Terminal.Gui/Application/Application.cs +++ b/Terminal.Gui/Application/Application.cs @@ -48,7 +48,7 @@ public static partial class Application internal static List GetSupportedCultures () { - CultureInfo [] culture = CultureInfo.GetCultures (CultureTypes.AllCultures); + CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures); // Get the assembly var assembly = Assembly.GetExecutingAssembly (); @@ -57,15 +57,37 @@ public static partial class Application string assemblyLocation = AppDomain.CurrentDomain.BaseDirectory; // Find the resource file name of the assembly - var resourceFilename = $"{Path.GetFileNameWithoutExtension (AppContext.BaseDirectory)}.resources.dll"; + var resourceFilename = $"{assembly.GetName ().Name}.resources.dll"; - // Return all culture for which satellite folder found with culture code. - return culture.Where ( - cultureInfo => - Directory.Exists (Path.Combine (assemblyLocation, cultureInfo.Name)) - && File.Exists (Path.Combine (assemblyLocation, cultureInfo.Name, resourceFilename)) - ) - .ToList (); + if (cultures.Length > 1 && Directory.Exists (Path.Combine (assemblyLocation, "pt-PT"))) + { + // Return all culture for which satellite folder found with culture code. + return cultures.Where ( + cultureInfo => + Directory.Exists (Path.Combine (assemblyLocation, cultureInfo.Name)) + && File.Exists (Path.Combine (assemblyLocation, cultureInfo.Name, resourceFilename)) + ) + .ToList (); + } + + // It's called from a self-contained single.file. + try + { + // false + return + [ + new ("fr-FR"), + new ("ja-JP"), + new ("pt-PT"), + new ("zh-Hans") + ]; + } + catch (CultureNotFoundException) + { + // true + // Only the invariant culture is supported in globalization-invariant mode. + return []; + } } // When `End ()` is called, it is possible `RunState.Toplevel` is a different object than `Top`. diff --git a/UnitTests/Application/ApplicationTests.cs b/UnitTests/Application/ApplicationTests.cs index a7c1fc64a..e2d707e3d 100644 --- a/UnitTests/Application/ApplicationTests.cs +++ b/UnitTests/Application/ApplicationTests.cs @@ -193,6 +193,7 @@ public class ApplicationTests // Internal properties Assert.False (Application._initialized); Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures); + Assert.Equal (4, Application.SupportedCultures.Count); Assert.False (Application._forceFakeConsole); Assert.Equal (-1, Application._mainThreadId); Assert.Empty (Application._topLevels);