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.

Mansfield
  • 14,445
  • 18
  • 76
  • 112
Luci
  • 3,174
  • 7
  • 31
  • 36
  • Do you mean language or script? Also, what kind of content do you want to do the detecting on? – Pekka Aug 27 '10 at 08:47
  • I want to know if text is arabic or not using java script. – Luci Aug 27 '10 at 08:51
  • [`\p` match generic character types](http://de.php.net/manual/en/regexp.reference.unicode.php), not exactly language – Gordon Aug 27 '10 at 08:52

3 Answers3

2

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

Community
  • 1
  • 1
powtac
  • 40,542
  • 28
  • 115
  • 170
  • 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 " – Luci Aug 27 '10 at 08:52
  • @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. – Chetan S Aug 27 '10 at 09:14
0

Wouldn't it be easier to use qTranslate?

Julian
  • 175
  • 1
  • 2
  • 13
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>
nonouco
  • 1,170
  • 1
  • 13
  • 25