asp.net-core - 如何在从右到左的文化本地化 ASP.Net core 2.2 应用程序中启用 RTL 模式?

标签 asp.net-core razor localization right-to-left globalization

我启用了本地化和全局化配置,需要在 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/

相关文章:

asp.net-mvc - Kendo Grid 更改列文本 - MVC 5、Razor

asp.net-mvc - Razor 中的for循环问题

c# - 为什么 Application Insights 依赖关系时间线存在间隙?

c# - 全局装配引用?

c# - 如何使用 ReadAsync 将 http 正文变成 dot net core 2.0 中的字符串

c# - 带连字符的友好 URL 路由

javascript - MVC3 Razor - Jquery 的 Foreach 问题

unicode - ICU/CLDR/UCA 支持哪些日语排序/整理顺序?

python - 区域设置和温度/长度转换

ios - iOS 中的马来语