Luci
Luci

Reputation: 3274

How to detect language in JavaScript?

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.

Upvotes: 0

Views: 1236

Answers (3)

nonouco
nonouco

Reputation: 1170

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>

Upvotes: 0

Julian
Julian

Reputation: 175

Wouldn't it be easier to use qTranslate?

Upvotes: 0

powtac
powtac

Reputation: 41080

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

Upvotes: 2

Related Questions