简体   繁体   中英

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.

您可以通过Google Language API通过PHP中的字符串检测语言来完成此操作

使用qTranslate会更容易吗?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM