Html language direction? (if English dir = ltr, if Arabic dir = rtl)

Can I do it?

I mean, if, for example, the contents <div>are Hebrew or Arabic, float <div>to the right and assign an attribute to it dir="rtl". And, if the content <div>is English, float to the left and change the attribute dirto "ltr".

Ss, what is possible?

+3
source share
3 answers

If you do not know the language, you can use the regular expression to search for Hebrew or Arabic characters, and then set the direction accordingly.

Use regular expressions to search for Hebrew: Javascript - how to find Hebrew?

Unicode, , : http://www.regular-expressions.info/unicode.html#block

+2

, , ( , , cookie?) php javascript .

0

dir div:

<div lang="ar" dir="rtl"><!-- some content here --></div>
<div lang="en" dir="ltr"><!-- some content here --></div>

This will automatically change the stream. However, you may need to customize certain elements depending on the language. You can do this using the CSS lang pseudo-language:

p:lang(ar) { text-align: right; }
p:lang(en) { text-align: left; }

Of course you could do this:

div:lang(en) { direction: ltr; }
div:lang(ar) { direction: rtl; }

This is an unacceptable method. Since you need to somehow set the language, you can also set the dir attribute. If you do this in some programming language, then you can usually determine the direction for a given spoken language (Locale, Culture, whatever). But that would be a different issue.

0
source

All Articles