简体   繁体   English

使jQuery字符串加载gettext

[英]Make jQuery strings load gettext

I have the following JavaScript (jQuery) snippet of code to load the flex slider in a WordPress theme and to add "prev" and "next" strings: 我有以下JavaScript(jQuery)代码段,以WordPress主题加载flex滑块并添加“ prev”和“ next”字符串:

 <script type="text/javascript"> 
   // FLEXSLIDER
   jQuery(window).load(function() {
     jQuery('.flexslider<?php echo $post_id; ?>').flexslider({
       controlNav: false,
       slideshow: false,
       prevText: "Prev", // String: Set the text for the "previous" directionNav item
       nextText: "Next",  
       controlsContainer: ".home-navigation<?php echo $post_id; ?>"
     });
   });                  
 </script>

The thing is that I want these strings to be loaded from my gettext .mo file so that it loads in German or English when appropriate. 问题是我希望从我的gettext .mo文件中加载这些字符串,以便在适当的时候以德语或英语加载。 I tried by adding: 我尝试通过添加:

prevText: "<?php echo gettext("Prev"); ?>"

as it is a php file, but it did not work somehow. 由于它是一个php文件,但无法正常工作。 Could be a quotes issue or something else. 可能是报价问题或其他问题。 Not sure yet. 尚未确定。

How can I load gettext data instead of these static strings? 如何加载gettext数据而不是这些静态字符串?

<script type="text/javascript"> 
 // FLEXSLIDER
 jQuery(window).load(function() {
   jQuery('.flexslider<?php echo $post_id; ?>').flexslider({
     controlNav: false,
     slideshow: false,
     prevText: '<?php echo gettext("Prev"); ?>',
     nextText: "Next",  
     controlsContainer: ".home-navigation<?php echo $post_id; ?>"
   });
 });                  
</script>

Was a question of loading the proper text domain. 是加载正确的文本域的问题。 Was working with one for child theme and parent theme. 正在与一个儿童主题和父母主题合作。 Once I adjusted some text domains and turned them into child theme text domains the changed gettext data was properly loaded. 一旦我调整了一些文本域并将其转换为子主题文本域,更改的gettext数据便会正确加载。 I made changes, which were not shown because the parent theme text domain loaded the old data while I added new data to the child theme .mos. 我进行了更改,但未显示出来,因为父主题文本域加载了旧数据,而我又向子主题.mos添加了新数据。 All OK now. 现在一切正常。 Thanks @Elliott for his help earlier on! 感谢@Elliott之前的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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