0

I know that in Wordpress we can do the following:

preg_match("/\p{Arabic}/u",
get_the_title())

How can we do this in JavaScript? Thanks in advance.

3
  • Do you mean language or script? Also, what kind of content do you want to do the detecting on? Commented Aug 27, 2010 at 8:47
  • I want to know if text is arabic or not using java script. Commented Aug 27, 2010 at 8:51
  • \p match generic character types, not exactly language Commented Aug 27, 2010 at 8:52

3 Answers 3

2

You could do this via the Google Language API Detect language from string in PHP

Sign up to request clarification or add additional context in comments.

2 Comments

I know how to detect language on php, I showed you that I know how! I want to do that on the client side " Java script "
@zeina: Did you see the answers in that link? There is an example that uses javascript (and AJAX) to detect the language. Javascript alone, as a language, does not have that capability.
0

Since you know how to detect your language in php then its just a simple matter of passing a value from your php code to your javascript code.

eg.

<?php $language = get_language_on_whatever_way_you_want(); ?>
<script type="text/javascript">
function alertMeTheLanguage() {
    var language = '<?php echo $language; ?>';
   alert('Your language is  <?php     echo $language; ?> ' );
}
</script>

1 Comment

Why do you use a the echo() twice instead of the JS variable language?
0

Wouldn't it be easier to use qTranslate?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.