语言识别和自动文本框方向切换 [英] Language recognition and automatic textbox direction switch

查看:154
本文介绍了语言识别和自动文本框方向切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个使用以下代码的HTML文本框:

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.

我的问题不是不是如何使用CSS声明特定方向.请不要在这里使用CSS.

My question is not how to declare specific direction using CSS. Please no CSS here.

我的问题是,是否有可能使用javascript自动检测语言,并查看它是从右到左的语言,还是使文本方向从右到左,还是从左到右? -右语言,使文本方向从左到右. (又名,它可能会自动检测语言,然后将CSS设置为"direction:rtl;"或其他内容).

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

使用JavaScript可以完成此操作吗? (我知道google在其Google翻译中做到了这一点,其他各个网站也做到了,我只是想知道是否难以实现)...

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

谢谢, 阿米特(Amit)

Thanks, Amit

推荐答案

使用Google API!他们在这里有一个语言检测"示例: http://code.google.com/apis/ajax/playground/#language_detect

Use the Google API! They have a Language Detect example here: http://code.google.com/apis/ajax/playground/#language_detect

-

我要做的是创建一个包含两列的数据库:"LANGUAGE"和"FORMAT".使用语言/格式(即"fr"和从左到右")填写数据库,然后从Google API获取语言结果后,便会在数据库中找到它并获取其格式.

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.

这篇关于语言识别和自动文本框方向切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆