Skip to content

Commit

Permalink
fix(templates): resolve Boilerplate without multilingual feature issu…
Browse files Browse the repository at this point in the history
…e in Blazor WASM #7718 (#7724)
  • Loading branch information
ysmoradi authored Jun 6, 2024
1 parent b9e77a6 commit 8ea2891
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ public static string GetApiServerAddress(this IConfiguration configuration)
{
var apiServerAddress = configuration.GetValue("ApiServerAddress", defaultValue: "/")!;

if (BuildConfiguration.IsDebug() &&
apiServerAddress.Contains("localhost", StringComparison.InvariantCultureIgnoreCase) &&
OperatingSystem.IsAndroid())
{
const string androidEmulatorDevMachineIP = "10.0.2.2"; // Special alias to your host loopback interface in Android Emulators (127.0.0.1 on your development machine)

apiServerAddress = apiServerAddress.Replace("localhost", androidEmulatorDevMachineIP, StringComparison.InvariantCultureIgnoreCase);
}

return Uri.TryCreate(apiServerAddress, UriKind.RelativeOrAbsolute, out _)
? apiServerAddress.TrimEnd('/')
: throw new InvalidOperationException($"Api server address {apiServerAddress} is invalid");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace Boilerplate.Shared.Services;

public class CultureInfoManager
{
public static CultureInfo DefaultCulture { get; } = CreateCultureInfo("en-US");
public static CultureInfo DefaultCulture => CreateCultureInfo("en-US");

public static (string DisplayName, CultureInfo Culture)[] SupportedCultures { get; } =
public static (string DisplayName, CultureInfo Culture)[] SupportedCultures =>
[
("English US", CreateCultureInfo("en-US")),
("English UK", CreateCultureInfo("en-GB")),
Expand Down Expand Up @@ -37,7 +37,7 @@ public void SetCurrentCulture(string cultureName)
/// <summary>
/// This is an example to demonstrate the way you can customize application culture
/// </summary>
public static CultureInfo CustomizeCultureInfoForFaCulture(CultureInfo cultureInfo)
private static CultureInfo CustomizeCultureInfoForFaCulture(CultureInfo cultureInfo)
{
cultureInfo.DateTimeFormat.AMDesignator = "ق.ظ";
cultureInfo.DateTimeFormat.PMDesignator = "ب.ظ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ public partial class Footer

protected override async Task OnInitAsync()
{
cultures = CultureInfoManager.SupportedCultures
.Select(sc => new BitDropdownItem<string> { Value = sc.Culture.Name, Text = sc.DisplayName })
.ToArray();
if (AppRenderMode.MultilingualEnabled)
{
cultures = CultureInfoManager.SupportedCultures
.Select(sc => new BitDropdownItem<string> { Value = sc.Culture.Name, Text = sc.DisplayName })
.ToArray();

SelectedCulture = CultureInfo.CurrentUICulture.Name;
SelectedCulture = CultureInfo.CurrentUICulture.Name;
}

await base.OnInitAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public MainWindow()
services.ConfigureServices();
InitializeComponent();
BlazorWebView.Services = services.BuildServiceProvider();
BlazorWebView.Services.GetRequiredService<CultureInfoManager>().SetCurrentCulture(App.Current.Properties["Culture"]?.ToString() ?? CultureInfo.CurrentUICulture.Name);
if (AppRenderMode.MultilingualEnabled)
{
BlazorWebView.Services.GetRequiredService<CultureInfoManager>().SetCurrentCulture(App.Current.Properties["Culture"]?.ToString() ?? CultureInfo.CurrentUICulture.Name);
}
BlazorWebView.Services.GetRequiredService<IPubSubService>().Subscribe(PubSubMessages.CULTURE_CHANGED, async culture =>
{
App.Current.Shutdown();
Expand Down

0 comments on commit 8ea2891

Please sign in to comment.