使用 CSS 文件进行站点本地化

发布于 2024-09-11 08:04:10 字数 204 浏览 3 评论 0原文

我正在使用 ASP.net MVC 2.0 创建一个网站,该网站使用两种不同的语言(英语和波斯语)。我想要这些语言有两种不同的布局,英语有从左到右的布局,波斯语有从右到左的布局。

我想到的是,如果我可以有两个不同的 css 文件,就像当你使用字符串或图像本地化来完成网站的工作一样,问题是我需要知道如何做到这一点!

关于如何执行此操作的任何其他建议都会有所帮助。

I'm creating a website with ASP.net MVC 2.0 which uses two different languages (English and Persian). I want to have two different layouts for these languages, English has a left to right and Persian has a right to left layout.

What came to my mind was, if I could have two different css files, like when you do it with string or image localization will do the work for the site, the problem is I need to know how to do this!

Any other suggestions on how to perform this would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鼻尖触碰 2024-09-18 08:04:13

您可以使用此代码在客户端获取区域设置。定义区域设置后,您可以在标头中动态包含样式表。

if ( navigator ) {
    if ( navigator.language ) {
        return navigator.language;
    }
    else if ( navigator.browserLanguage ) {
        return navigator.browserLanguage;
    }
    else if ( navigator.systemLanguage ) {
        return navigator.systemLanguage;
    }
    else if ( navigator.userLanguage ) {
        return navigator.userLanguage;
    }
}

This is the code you can use to get the Locale at the client side. Once you have the locale defined, you can dynamically include a stylesheet in the header.

if ( navigator ) {
    if ( navigator.language ) {
        return navigator.language;
    }
    else if ( navigator.browserLanguage ) {
        return navigator.browserLanguage;
    }
    else if ( navigator.systemLanguage ) {
        return navigator.systemLanguage;
    }
    else if ( navigator.userLanguage ) {
        return navigator.userLanguage;
    }
}
゛清羽墨安 2024-09-18 08:04:13

不确定这是否是您想要的,但几年前我用 VBScript 做到了这一点。不理想,但它对我有用:

弄清楚语言:

<%
Dim sLanguage
sLanguage = Request.QueryString("lang")

Dim userLocale
userLocale=Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

Dim sDomain
sDomain = Request.ServerVariables("HTTP_HOST")

Dim languages
languages = Split(userLocale, ",", -1)


...

设置样式表...

<% select case MasterLanguage
    case "PORTUGUESE"%>
        <style media="screen" type="text/css">@import "/Includes/css/a_formatting.css";</style>
        <style media="screen" type="text/css">@import "/includes/langs/br/languageSpecific.css";</style>
        <link type="text/css" media="print" rel="stylesheet" href="/Includes/css/print.css" />
<%
case "SIMPCHINESE"
%>
        <style media="screen" type="text/css">@import "/Includes/css/a_formatting_zh-cn.css";</style>
        <style media="screen" type="text/css">@import "/includes/langs/zh-cn/languageSpecific.css";</style>
        <link type="text/css" media="print" rel="stylesheet" href="/Includes/css/print_zh-cn.css" />
<%

如果这有帮助,我可以发布更多片段。

Not sure if this is what you ar elooking for, but I did this a few years back in VBScript. Not ideal, but it works for me:

Figure out the language:

<%
Dim sLanguage
sLanguage = Request.QueryString("lang")

Dim userLocale
userLocale=Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

Dim sDomain
sDomain = Request.ServerVariables("HTTP_HOST")

Dim languages
languages = Split(userLocale, ",", -1)


...

Set the style sheet...

<% select case MasterLanguage
    case "PORTUGUESE"%>
        <style media="screen" type="text/css">@import "/Includes/css/a_formatting.css";</style>
        <style media="screen" type="text/css">@import "/includes/langs/br/languageSpecific.css";</style>
        <link type="text/css" media="print" rel="stylesheet" href="/Includes/css/print.css" />
<%
case "SIMPCHINESE"
%>
        <style media="screen" type="text/css">@import "/Includes/css/a_formatting_zh-cn.css";</style>
        <style media="screen" type="text/css">@import "/includes/langs/zh-cn/languageSpecific.css";</style>
        <link type="text/css" media="print" rel="stylesheet" href="/Includes/css/print_zh-cn.css" />
<%

I can post more snippets if this is helpful.

℡寂寞咖啡 2024-09-18 08:04:12

您可以阅读:

在您的页面中:

  • 每个带有文本的图像都应该被翻译(图像和alt);每个具有方向性的图像都应该反转(例如:箭头),
  • 如果您不想将来遇到麻烦,请尝试避免像 class="left" 这样的类命名。顶部、底部、之前或之后都可以,但左/右不行(编辑:CSS3 中现在使用 startend 来避免 ltr 和 rtl 的这种确切问题。比已经用于带有冒号的伪符号的 *-before*-after 更好)。
  • 您必须检查有关 text-alignbackground-positionfloatclear 和显然位置:绝对/相对;。新的 CSS3 指令也要回顾(动画等)。
  • 不同的字体需要不同的字体大小(尽管这个问题主要涉及亚洲字体),
  • 对于任何其他支持的语言,模板中的许多文本都应该被翻译。

如上面的链接所述,使用了 HTML 属性 dir="rtl"。您还需要一个类(在 body 上或某些包含 div 的类上,以充当满足您设计需求的巨型开关。就像

.en .yourclass { background: url(images/en/bg.jpg) } 
.ar .yourclass { background: url(images/ar/bg.jpg) }

属性选择器一样,因为 IE8 包含了。

:lang(ar) .yourclass { background: url(images/ar/bg.jpg) }
or
[lang|="ar"] .yourclass { background: url(images/ar/bg.jpg) }

You can read about:

In your pages:

  • every image with text should be translated (image and alt); every image with directionality should be reversed (ex: an arrow)
  • try to avoid class naming like class="left" if you don't want future headaches. Top, bottom, before or after are OK but not left/right (edit: start and end are now used in CSS3 to avoid this exact problem of ltr and rtl. May be better than *-before and *-after already used for pseudos with colons).
  • you'll have to check each CSS instruction about text-align, background-position, float, clear and obviously left and right with position: absolute/relative;. New CSS3 instructions are to review too (Animations, etc).
  • different fonts need different font sizes (though this problem concerns asiatic fonts mainly)
  • as for any other supported language, many bits of text in templates should be translated.

As noted in the links above, the HTML attribute dir="rtl" is used. You'll also need a class (on body or some containing div to act like a giant switch for your design needs. Like

.en .yourclass { background: url(images/en/bg.jpg) } 
.ar .yourclass { background: url(images/ar/bg.jpg) }

The attribute selector does the same, since IE8 included.

:lang(ar) .yourclass { background: url(images/ar/bg.jpg) }
or
[lang|="ar"] .yourclass { background: url(images/ar/bg.jpg) }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文