简体   繁体   English

在Flip切换开关jQuery Mobile中更改文本

[英]Change the text in a Flip toggle switch, jQuery Mobile

I am working on a multilingual iOS/Android app and use a xml file to get my translations. 我正在使用多语言iOS / Android应用程序,并使用xml文件获取翻译。 The translation function looks for a i18n-xxx class and replaces the text for html elements with that class with the text from the xml file. 转换功能将查找i18n-xxx类,并用xml文件中的文本替换该类的html元素的文本。

Example: 例:

Html: HTML:

<a href="url.html" data-role="button" class="i18n-my-button">Button</a>

In the xml file: 在xml文件中:

<translation id="i18n-my-button">
   <en>Button</en>
   <sv>Knapp</sv>
</translation>

Javascript: Javascript:

...
$(xml).find("translation").each(function() {
   ...
   var id = $(this).attr("id"); //i18n-my-button
   var translation = $(this).find("sv").text();  //Knapp
   ...
   $("." + id).find("span.ui-btn-text").text(translation);
});

With this approach I am able to translate almost any html element like buttons, radio buttons and check boxes. 通过这种方法,我几乎可以翻译任何HTML元素,例如按钮,单选按钮和复选框。 But I am failing to translate flip toggle switches. 但是我无法转换拨动开关。

This is how I would like it to be: 这就是我希望的样子:

<select name="slider" id="flip-a" data-role="slider">
    <option value="off" class="i18n-off">Off</option>
    <option value="on" class="i18n-on">On</option>
</select>

I want to be able to translate "Off" and "On" to "Av" and "På" using the same function as with the other html elements. 我希望能够使用与其他html元素相同的功能将“关闭”和“打开”转换为“ Av”和“På”。 The problem is jQuery Mobile translates the simple select to a huge block of code, and I have not yet identified what element I should translate and how to do it. 问题是jQuery Mobile将简单的select转换为大量代码,而我尚未确定应该转换的元素以及如何执行。

Any suggestions? 有什么建议么?

You could hook into the create event fired when a slider is styled/created by JQM. 您可以插入由JQM设置样式/创建滑块时触发的create事件。

$( ".selector" ).slider({
   create: function(event, ui) { 
      //Do translation here
   }
});

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

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