Merge branch 'v2_develop' into v2_2491-Refactor-TopLevel-Application-And-Focus

This commit is contained in:
Tig
2024-08-02 13:18:39 -04:00
committed by GitHub
14 changed files with 250 additions and 263 deletions

View File

@@ -2,6 +2,8 @@
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using Terminal.Gui.Resources;
namespace Terminal.Gui;
@@ -26,7 +28,7 @@ public static partial class Application
internal static List<CultureInfo> GetSupportedCultures ()
{
CultureInfo [] culture = CultureInfo.GetCultures (CultureTypes.AllCultures);
CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures);
// Get the assembly
var assembly = Assembly.GetExecutingAssembly ();
@@ -35,15 +37,35 @@ 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 and get available cultures from the embedded resources strings.
return GetAvailableCulturesFromEmbeddedResources ();
}
internal static List<CultureInfo> GetAvailableCulturesFromEmbeddedResources ()
{
ResourceManager rm = new (typeof (Strings));
CultureInfo [] cultures = CultureInfo.GetCultures (CultureTypes.AllCultures);
return cultures.Where (
cultureInfo =>
!cultureInfo.Equals (CultureInfo.InvariantCulture)
&& rm.GetResourceSet (cultureInfo, true, false) is { }
)
.ToList ();
}
// IMPORTANT: Ensure all property/fields are reset here. See Init_ResetState_Resets_Properties unit test.