From 579e06ba8bee27e9124c2ee935438fb1180479bd Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Thu, 12 Sep 2024 10:54:19 -0400 Subject: [PATCH] chore: Add support for WasmShellLoadAllSatelliteResources --- doc/deploy-and-publish.md | 8 ++++++++ doc/using-the-bootstrapper.md | 12 ++++++++++++ src/Uno.Wasm.Bootstrap/ShellTask.cs | 3 +++ .../build/Uno.Wasm.Bootstrap.targets | 1 + .../ts/Uno/WebAssembly/Bootstrapper.ts | 3 ++- .../ts/Uno/WebAssembly/UnoConfig.ts | 2 ++ src/Uno.Wasm.Sample/Program.cs | 14 +++++++++++++- src/Uno.Wasm.Sample/sample.common.props | 2 ++ 8 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/deploy-and-publish.md b/doc/deploy-and-publish.md index 20337ef..f57e6c9 100644 --- a/doc/deploy-and-publish.md +++ b/doc/deploy-and-publish.md @@ -14,6 +14,14 @@ dotnet publish The app will be located in the `bin/Release/net9.0/publish/wwwroot` folder. More information about `dotnet publish` can be [found in the Microsoft docs](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish). +## Localization publishing +By default, the .NET runtime does not load all resource assemblies, but if you want to load all resources regardless of the user's culture, you can add the following to your project file: +```xml + + true + +``` + ## Integration with ASP.NET Core ASP.NET Core hosting is supported through the `Uno.Wasm.Bootstrap.Server` package. diff --git a/doc/using-the-bootstrapper.md b/doc/using-the-bootstrapper.md index 6ac2e24..10a272f 100644 --- a/doc/using-the-bootstrapper.md +++ b/doc/using-the-bootstrapper.md @@ -88,6 +88,13 @@ Once done, make sure to install the WebAssembly tools from .NET: dotnet workload install wasm-tools ``` +By default, the .NET runtime does not load all resource assemblies, but if you want to load all resources regardless of the user's culture, you can add the following to your project file: +```xml + + true + +``` + ## Bootstrapper versions and .NET runtimes Each major version of the bootstrapper targets a different version of the .NET Runtime. @@ -103,3 +110,8 @@ Each major version of the bootstrapper targets a different version of the .NET R > > [!NOTE] > Bootstrapper builds version 4.x-dev were based on developments builds of .NET 7 and were later versioned 7.x-dev to match the appropriate runtime. + +## Previous releases documentation +- [8.0.x](https://github.com/unoplatform/Uno.Wasm.Bootstrap/tree/release/stable/8.0/doc) +- [7.0.x](https://github.com/unoplatform/Uno.Wasm.Bootstrap/tree/release/stable/7.0/doc) +- [3.x](https://github.com/unoplatform/Uno.Wasm.Bootstrap/tree/release/stable/3.3/doc) diff --git a/src/Uno.Wasm.Bootstrap/ShellTask.cs b/src/Uno.Wasm.Bootstrap/ShellTask.cs index 17ffcd5..0d03194 100644 --- a/src/Uno.Wasm.Bootstrap/ShellTask.cs +++ b/src/Uno.Wasm.Bootstrap/ShellTask.cs @@ -102,6 +102,8 @@ namespace Uno.Wasm.Bootstrap public bool EnableTracing { get; set; } + public bool LoadAllSatelliteResources { get; set; } + public string AotProfile { get; set; } = ""; public bool RunAOTCompilation { get; set; } @@ -531,6 +533,7 @@ namespace Uno.Wasm.Bootstrap config.AppendLine($"config.uno_shell_mode = \"{_shellMode}\";"); config.AppendLine($"config.uno_debugging_enabled = {(!Optimize).ToString().ToLowerInvariant()};"); config.AppendLine($"config.uno_enable_tracing = {EnableTracing.ToString().ToLowerInvariant()};"); + config.AppendLine($"config.uno_load_all_satellite_resources = {LoadAllSatelliteResources.ToString().ToLowerInvariant()};"); config.AppendLine($"config.emcc_exported_runtime_methods = [{emccExportedRuntimeMethodsParams}];"); if (GenerateAOTProfile) diff --git a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets index e2e259d..f44c93a 100644 --- a/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets +++ b/src/Uno.Wasm.Bootstrap/build/Uno.Wasm.Bootstrap.targets @@ -254,6 +254,7 @@ GenerateAOTProfile="$(WasmShellGenerateAOTProfile)" IndexHtmlPath="$(WasmShellIndexHtmlPath)" IntermediateOutputPath="$(IntermediateOutputPath)" + LoadAllSatelliteResources="$(WasmShellLoadAllSatelliteResources)" LogProfilerOptions="$(WasmShellLogProfilerOptions)" MonoEnvironment="@(WasmShellMonoEnvironment)" PublishTrimmed="$(PublishTrimmed)" diff --git a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts index e3a1318..ec4bccb 100644 --- a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts +++ b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/Bootstrapper.ts @@ -101,7 +101,8 @@ namespace Uno.WebAssembly.Bootstrap { .withModuleConfig({ preRun: () => bootstrapper.wasmRuntimePreRun(), }) - .withRuntimeOptions(config.config.uno_runtime_options); + .withRuntimeOptions(config.config.uno_runtime_options) + .withConfig({ loadAllSatelliteResources: config.config.uno_loadAllSatelliteResources }); const dotnetRuntime = await m.default( (context: DotnetPublicAPI) => { diff --git a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/UnoConfig.ts b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/UnoConfig.ts index 127a400..786b0cb 100644 --- a/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/UnoConfig.ts +++ b/src/Uno.Wasm.Bootstrap/ts/Uno/WebAssembly/UnoConfig.ts @@ -32,5 +32,7 @@ uno_debugging_enabled?: boolean; uno_runtime_options?: string[]; + + uno_load_all_satellite_resources?: string[]; } } diff --git a/src/Uno.Wasm.Sample/Program.cs b/src/Uno.Wasm.Sample/Program.cs index 0b891a1..9224eae 100644 --- a/src/Uno.Wasm.Sample/Program.cs +++ b/src/Uno.Wasm.Sample/Program.cs @@ -19,6 +19,8 @@ using System.Threading; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Globalization; +using System.Runtime.InteropServices.JavaScript; +using System.Threading.Tasks; namespace Uno.Wasm.Sample { @@ -59,13 +61,20 @@ namespace Uno.Wasm.Sample #endif Console.WriteLine($"requireJSAvailable: {requireAvailable}"); + Console.WriteLine($"CultureInfo.CurrentCulture: {CultureInfo.CurrentCulture}"); + Console.WriteLine($"CultureInfo.CurrentUICulture: {CultureInfo.CurrentUICulture}"); + Console.WriteLine($"Thread.CurrentThread.CurrentCulture: {Thread.CurrentThread.CurrentCulture}"); + Console.WriteLine($"Thread.CurrentThread.CurrentUICulture: {Thread.CurrentThread.CurrentUICulture}"); + Console.WriteLine($"CultureInfo.DefaultThreadCurrentCulture: { CultureInfo.DefaultThreadCurrentCulture?.ToString() ?? "" }"); + Console.WriteLine($"CultureInfo.DefaultThreadCurrentUICulture: { CultureInfo.DefaultThreadCurrentUICulture?.ToString() ?? ""}"); + Console.WriteLine($"Timezone: {TimeZoneInfo.Local.StandardName}"); Console.WriteLine(typeof(Microsoft.Extensions.Logging.Abstractions.NullLogger)); var r = new System.Resources.ResourceManager("FxResources.System.Web.Services.Description.SR", typeof(System.Web.Services.Description.Binding).Assembly); Console.WriteLine($"Res(en): {r.GetString("WebDescriptionMissing", new CultureInfo("en-US"))}"); - Console.WriteLine($"Res(fr): {r.GetString("WebDescriptionMissing", new CultureInfo("fr-CA"))}"); + Console.WriteLine($"Res(fr): {r.GetString("WebDescriptionMissing", new CultureInfo("fr"))}"); _t = new Timer(_ => { Console.WriteLine("message"); @@ -84,6 +93,9 @@ namespace Uno.Wasm.Sample [System.Runtime.InteropServices.JavaScript.JSImport("globalThis.isRequireAvailable")] public static partial bool IsRequireAvailable(); + + [JSImport("INTERNAL.loadSatelliteAssemblies")] + internal static partial Task LoadSatelliteAssemblies(string[] culturesToLoad); } #endif diff --git a/src/Uno.Wasm.Sample/sample.common.props b/src/Uno.Wasm.Sample/sample.common.props index 0189e59..8976d61 100644 --- a/src/Uno.Wasm.Sample/sample.common.props +++ b/src/Uno.Wasm.Sample/sample.common.props @@ -21,6 +21,8 @@ Uno.Wasm.SampleNet7 true + + true