Using a CSS File for site localization

前端 未结 3 1938
灰色年华
灰色年华 2021-02-09 02:42

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 le

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 02:47

    You can read about:

    • (W3C) Internationalization Best Practices: Specifying Language in XHTML & HTML Content,
    • Creating HTML Pages in Arabic, Hebrew and Other Right-to-left Scripts,
    • Internationalization and localization (Wikipedia).

    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) }
    

提交回复
热议问题