根据语言更改文本 [英] Change text depending on language

查看:72
本文介绍了根据语言更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有语言切换器的Wordpress在各种语言之间进行切换.在模板中,我正在使用这段代码来切换硬编码文本.

I'm using Wordpress with a language switcher to switch between various languages. Within the templates I'm using this piece of code to switch hard coded text.

<?php if(ICL_LANGUAGE_CODE == 'en') { ?>
   This is english
<?php } else { ?>
   This is another language
<?php } ?>

我有一个侧边栏,但是它是通过各种小部件创建的,所以我无法放置相同的修复程序.

I have a sidebar but it's created via various widgets so I can't put the same fix in place.

使用jquery,如何定位特定div中的所有文本并将其替换为其他内容?

Using jquery, how can I target all the text within a specific div and replace it with something else?

如果我在上面的代码中放入该jquery,那应该行得通吗?

If I put that jquery within the code above then that should work shouldn't it?

推荐答案

jQuery/JS是Client,PHP是服务器,因此,有一种将PHP注入JavaScript的机会,那就是在运行时页面的.您可能可以执行以下操作:

jQuery/JS is Client, PHP is server, so that being said, there is one chance to inject PHP into JavaScript, and that is at the run-time of the page. You can probably do something like:

$(document).ready(function() {
    var language = '<?php echo ICL_LANGUAGE_CODE?>';
    if (language == "EN") {
        $("#IDOFDIV").html("NEW HTML HERE");
    }
});

这篇关于根据语言更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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