Language recognition and automatic textbox direction switch
Say I have a textbox in HTML using the following code:
<input type="text" name="text" id="开发者_开发百科text" />
And my site is intended to be for right-to-left as well as left-to-right languages. That means that I have some textboxes that will be typed in a right-to-left language, but the email textbox, for example, will be left-to-right.
My question is not how to declare specific direction using CSS. Please no CSS here.
My question is if it's possible to use javascript to automatically detect the language, and seeing if it's a right-to-left language, make the text-direction go from right-to-left, or if it's a left-to-right language, make the text direction go from left-to-right. (AKA, it could possibly auto detect the language, THEN set the CSS "direction: rtl;" or whatever).
Is this possible to accomplish using javascript? (I know google does it in their google translate and various other sites do it as well, I was just wondering if it's difficult to implement)...
Thanks, Amit
Use the Google API! They have a Language Detect example here: http://code.google.com/apis/ajax/playground/#language_detect
--
What I would do is create a database with two columns: "LANGUAGE" and "FORMAT". Fill in the database with the languages/formats (i.e "fr" and "left-to-right"), and when you get the language result from the Google API, you find it in your database and get its format.
精彩评论