Blazor UI: Add "rtl" class to body if the current language is RTL.

pull/5957/head
Halil İbrahim Kalkan 5 years ago
parent 72142ec0bb
commit 100f6f09b8

@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
using (var scope = serviceProvider.CreateScope())
{
await InitializeModulesAsync(scope.ServiceProvider);
SetCurrentLanguage(scope);
await SetCurrentLanguageAsync(scope);
}
}
@ -63,9 +63,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
}
}
private static void SetCurrentLanguage(IServiceScope scope)
private async static Task SetCurrentLanguageAsync(IServiceScope scope)
{
var configurationClient = scope.ServiceProvider.GetRequiredService<ICachedApplicationConfigurationClient>();
var utilsService = scope.ServiceProvider.GetRequiredService<IAbpUtilsService>();
var configuration = configurationClient.Get();
var cultureName = configuration.Localization?.CurrentCulture?.CultureName;
if (!cultureName.IsNullOrEmpty())
@ -74,6 +75,11 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Hosting
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
}
if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft)
{
await utilsService.AddClassToTagAsync("body", "rtl");
}
}
}
}

Loading…
Cancel
Save