Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Components/Web.JS/src/GlobalExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface IBlazor {
renderBatch?: (browserRendererId: number, batchAddress: Pointer) => void;
getConfig?: (fileName: string) => Uint8Array | undefined;
getApplicationEnvironment?: () => string;
getApplicationCulture?: () => string;
dotNetCriticalError?: any;
loadLazyAssembly?: any;
loadSatelliteAssemblies?: any;
Expand Down
1 change: 1 addition & 0 deletions src/Components/Web.JS/src/Platform/Mono/MonoPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function prepareRuntimeConfig(options: Partial<WebAssemblyStartOptions>, onConfi
}

Blazor._internal.getApplicationEnvironment = () => loadedConfig.applicationEnvironment!;
Blazor._internal.getApplicationCulture = () => loadedConfig.applicationCulture!;

onConfigLoadedCallback?.(loadedConfig);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal WebAssemblyCultureProvider(CultureInfo initialCulture, CultureInfo init
internal static void Initialize()
{
Instance = new WebAssemblyCultureProvider(
initialCulture: CultureInfo.CurrentCulture,
initialCulture: CultureInfo.GetCultureInfo(WebAssemblyCultureProviderInterop.GetApplicationCulture() ?? CultureInfo.InvariantCulture.Name),
initialUICulture: CultureInfo.CurrentUICulture);
}

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

[JSImport("Blazor._internal.getApplicationCulture", "blazor-internal")]
public static partial string GetApplicationCulture();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ internal interface IInternalJSImportMethods
string GetPersistedState();

string GetApplicationEnvironment();

string GetApplicationCulture();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public static async Task<RootComponentOperationBatch> GetInitialComponentUpdate(
public string GetApplicationEnvironment()
=> GetApplicationEnvironmentCore();

public string GetApplicationCulture()
=> GetApplicationCultureCore();

public void AttachRootComponentToElement(string domElementSelector, int componentId, int rendererId)
=> AttachRootComponentToElementCore(domElementSelector, componentId, rendererId);

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

[JSImport("Blazor._internal.getApplicationCulture", "blazor-internal")]
private static partial string GetApplicationCultureCore();

[JSImport("Blazor._internal.attachRootComponentToElement", "blazor-internal")]
private static partial void AttachRootComponentToElementCore(string domElementSelector, int componentId, int rendererId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public TestInternalJSImportMethods(string environment = "Production")

public string GetApplicationEnvironment()
=> _environment;

public string GetApplicationCulture()
=> "en-US";

public string GetPersistedState()
=> null;
Expand Down
Loading