Muh*_*del 2 globalization localization right-to-left razor asp.net-core
我启用了本地化和全球化配置,需要在 RTL Culture 中添加 RTL 模式。我该怎么做?
将 ASP.Net Core 2.2 与 razor 页面和个人帐户配置一起使用
// 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;
});
Run Code Online (Sandbox Code Playgroud)
选择 RTL Culture 时启用 RTL 模式
为 RTL 样式创建一个新的 css 文件,例如rtl.css
body {
direction:rtl;
}
Run Code Online (Sandbox Code Playgroud)
然后在 _layout.cshtml 文件中检查当前文化文本方向并在 head 部分包含相关的 css 文件;
@using System.Globalization
@if(CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) {
<link rel="stylesheet" type="text/css" href="rtl.css">
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1729 次 |
| 最近记录: |