Skip to content

Commit 1aee7a9

Browse files
committed
Changed initial culture detection
1 parent 0e3d342 commit 1aee7a9

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

src/Components/Web.JS/src/GlobalExports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export interface IBlazor {
7474
renderBatch?: (browserRendererId: number, batchAddress: Pointer) => void;
7575
getConfig?: (fileName: string) => Uint8Array | undefined;
7676
getApplicationEnvironment?: () => string;
77+
getApplicationCulture?: () => string;
7778
dotNetCriticalError?: any;
7879
loadLazyAssembly?: any;
7980
loadSatelliteAssemblies?: any;

src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ function prepareRuntimeConfig(options: Partial<WebAssemblyStartOptions>, onConfi
154154
}
155155

156156
Blazor._internal.getApplicationEnvironment = () => loadedConfig.applicationEnvironment!;
157+
Blazor._internal.getApplicationCulture = () => loadedConfig.applicationCulture!;
157158

158159
onConfigLoadedCallback?.(loadedConfig);
159160

src/Components/WebAssembly/WebAssembly/src/Hosting/WebAssemblyCultureProvider.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ internal WebAssemblyCultureProvider(CultureInfo initialCulture, CultureInfo init
3232
internal static void Initialize()
3333
{
3434
Instance = new WebAssemblyCultureProvider(
35-
initialCulture: CultureInfo.CurrentCulture,
35+
initialCulture: CultureInfo.GetCultureInfo(WebAssemblyCultureProviderInterop.GetApplicationCulture() ?? CultureInfo.InvariantCulture.Name),
3636
initialUICulture: CultureInfo.CurrentUICulture);
3737
}
3838

@@ -48,8 +48,7 @@ public void ThrowIfCultureChangeIsUnsupported()
4848
// The current method is invoked as part of WebAssemblyHost.RunAsync i.e. after user code in Program.MainAsync has run
4949
// thus allows us to detect if the culture was changed by user code.
5050
if (Environment.GetEnvironmentVariable("__BLAZOR_SHARDED_ICU") == "1" &&
51-
((!CultureInfo.CurrentCulture.Name.Equals(InitialCulture.Name, StringComparison.Ordinal) ||
52-
!CultureInfo.CurrentUICulture.Name.Equals(InitialUICulture.Name, StringComparison.Ordinal))))
51+
(!CultureInfo.CurrentCulture.Name.Equals(InitialCulture.Name, StringComparison.Ordinal)))
5352
{
5453
throw new InvalidOperationException("Blazor detected a change in the application's culture that is not supported with the current project configuration. " +
5554
"To change culture dynamically during startup, set <BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData> in the application's project file.");
@@ -118,5 +117,8 @@ private partial class WebAssemblyCultureProviderInterop
118117
{
119118
[JSImport("INTERNAL.loadSatelliteAssemblies")]
120119
public static partial Task LoadSatelliteAssemblies(string[] culturesToLoad);
120+
121+
[JSImport("Blazor._internal.getApplicationCulture", "blazor-internal")]
122+
public static partial string GetApplicationCulture();
121123
}
122124
}

src/Components/WebAssembly/WebAssembly/src/Services/IInternalJSImportMethods.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ internal interface IInternalJSImportMethods
88
string GetPersistedState();
99

1010
string GetApplicationEnvironment();
11+
12+
string GetApplicationCulture();
1113

1214
void AttachRootComponentToElement(string domElementSelector, int componentId, int rendererId);
1315

src/Components/WebAssembly/WebAssembly/src/Services/InternalJSImportMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public static async Task<RootComponentOperationBatch> GetInitialComponentUpdate(
2727
public string GetApplicationEnvironment()
2828
=> GetApplicationEnvironmentCore();
2929

30+
public string GetApplicationCulture()
31+
=> GetApplicationCultureCore();
32+
3033
public void AttachRootComponentToElement(string domElementSelector, int componentId, int rendererId)
3134
=> AttachRootComponentToElementCore(domElementSelector, componentId, rendererId);
3235

@@ -72,6 +75,9 @@ public string RegisteredComponents_GetParameterValues(int id)
7275
[JSImport("Blazor._internal.getApplicationEnvironment", "blazor-internal")]
7376
private static partial string GetApplicationEnvironmentCore();
7477

78+
[JSImport("Blazor._internal.getApplicationCulture", "blazor-internal")]
79+
private static partial string GetApplicationCultureCore();
80+
7581
[JSImport("Blazor._internal.attachRootComponentToElement", "blazor-internal")]
7682
private static partial void AttachRootComponentToElementCore(string domElementSelector, int componentId, int rendererId);
7783

src/Components/WebAssembly/WebAssembly/test/TestInternalJSImportMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ public TestInternalJSImportMethods(string environment = "Production")
1616

1717
public string GetApplicationEnvironment()
1818
=> _environment;
19+
20+
public string GetApplicationCulture()
21+
=> "en-US";
1922

2023
public string GetPersistedState()
2124
=> null;

0 commit comments

Comments
 (0)