我启用了本地化和全局化配置,需要在 RTL Culture 中添加 RTL 模式。我该怎么做?
使用带有 Razor 页面和个人帐户配置的 ASP.Net Core 2.2
// Configuration Of Localizaion
services.AddLocalization(opts =>
{
opts.ResourcesPath = "CultureResources";
});
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddMvc()
.AddViewLocalization(opts => { opts.ResourcesPath = "CultureResources"; })
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
.AddRazorPagesOptions(options =>
{
options.AllowAreas = true;
options.Conventions.AuthorizeAreaFolder("Identity", "/Account/Manage");
options.Conventions.AuthorizeAreaPage("Identity", "/Account/Logout");
});
services.Configure<RequestLocalizationOptions>(opt =>
{
var supportedCulutures = new List<CultureInfo>
{
new CultureInfo("en"),
new CultureInfo("en-US"),
new CultureInfo("ar-EG")
};
opt.DefaultRequestCulture = new RequestCulture("en-US");
// Formating numbers, date, etc.
opt.SupportedCultures = supportedCulutures;
// UI strings that we have localized
opt.SupportedUICultures = supportedCulutures;
});
选择 RTL Culture 时启用 RTL 模式
最佳答案
为 RTL 样式创建一个新的 css 文件,例如css文件
body {
direction:rtl;
}
然后在 _layout.cshtml 文件中检查当前文化文本方向并在 head 部分包含相关的 css 文件;
@using System.Globalization
@if(CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) {
<link rel="stylesheet" type="text/css" href="rtl.css">
}
关于asp.net-core - 如何在从右到左的文化本地化 ASP.Net core 2.2 应用程序中启用 RTL 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57022815/