Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a CSS File for site localization

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.

like image 522
Peymankh Avatar asked Jul 22 '10 17:07

Peymankh


People also ask

Can CSS be used for Localisation of a website?

Whether you are designing a different look for your regional site, or need a solution for fixing layout issues such as text expansion/truncation on a localized page, you can implement customized CSS for any localized site in GDN by referencing the Smartling language class.

How do I integrate a CSS file into my website?

CSS may be added to HTML in three different ways. To style a single HTML element on the page, use Inline CSS in a style attribute. By adding CSS to the head section of our HTML document, we can embed an internal stylesheet. We can also connect to an external stylesheet that separates our CSS from our HTML.

How do I reference a local CSS file in HTML?

CSS can be added to HTML documents in 3 ways: Inline - by using the style attribute inside HTML elements. Internal - by using a <style> element in the <head> section. External - by using a <link> element to link to an external CSS file.

Where should you import a CSS file?

css”; or directly import any CSS file or multiple CSS file in the HTML file directly within <style>@import “style1. css”; or . @import url(“style2. css”);</style> in head section.


1 Answers

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) }
like image 198
FelipeAls Avatar answered Sep 30 '22 09:09

FelipeAls