如何在从右到左文化本地化ASP.Net core 2.2应用程序中启用RTL模式? [英] How to enable RTL mode in Right-To-Left Culture Localization ASP.Net core 2.2 application?

查看:133
本文介绍了如何在从右到左文化本地化ASP.Net core 2.2应用程序中启用RTL模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已启用本地化和全球化配置,并且需要在RTL文化中添加RTL模式.我该怎么办?

I have enabled Localization and Globalization configuration and need to add RTL mode in RTL Culture. How Can i do it?

使用带有剃须刀页面和个人帐户配置的ASP.Net Core 2.2

Using ASP.Net Core 2.2 with razor pages and Individual account configuration

// 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文化"时启用RTL模式

RTL mode enabled when choose RTL Culture

推荐答案

为RTL样式创建新的CSS文件,例如 rtl.css

Create a new css file for RTL styles e.g. rtl.css

body {
    direction:rtl;
}

然后在_layout.cshtml文件中检查当前区域性文本的方向,并在头部添加相关的CSS文件;

Then in the _layout.cshtml file check for current culture text direction and include the relevant css file in the head section;

@using System.Globalization
@if(CultureInfo.CurrentCulture.TextInfo.IsRightToLeft) {
    <link rel="stylesheet" type="text/css" href="rtl.css">
}

这篇关于如何在从右到左文化本地化ASP.Net core 2.2应用程序中启用RTL模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆