views:

30

answers:

1

Hi everyone,

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

+1  A: 

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.

Jon McIntosh
I'll definitely give it a look right now, thanks!
Amit
That's exactly what I wanted. So now what should I do to implement that into my site? I'm sure I need to reference to the google language api somehow, right?
Amit
Got it. Perfect. Thank you.
Amit
I edited it with the methods *I* would use. As for referencing the Google APIs; the code should all be in that sandbox. If you click the 'Edit HTML' button, it will give you all of the code needed on your page. If you need the full documentation for the API, it'll be here:http://code.google.com/apis/ajaxlanguage/documentation/ .
Jon McIntosh