我想把按钮的标签从“开始”更改为“重新启动”。我的应用程序将以几种语言提供,我正在使用L10n.js库。按钮的标签可以有两个值(“开始”和“重新启动”),在app.properties中定义如下:
start = Start
restart = Restart
text = this is some text
another-text = this is another text按钮的定义如下(使用按钮构建块):
<body>
<p id="sometext" data-l10n-id="text"></p>
<section data-type="sidebar" role="region" class="skin-dark">
<section style="margin-bottom: 30px">
<button id="startbutton" class = "recommend" data-l10n-id="start">Start</button>
</section>
</div>
</section>
</body>加载页面后,将显示正确的按钮(和段落)值。数据-110n-id属性和相应的值应在单击时更改:
document.getElementById("startbutton").addEventListener("click", function( event ) {
this.setAttribute("data-l10n-id", "restart");
document.getElementById("sometext").setAttribute("data-l10n-id", "another-text");
});查看DOM,属性已经更改,但不应该显示它应该显示的值:
<p id="sometext" data-l10n-id="another-text">this is some text</p>
<section data-type="sidebar" role="region" class="skin-dark">
<section style="margin-bottom: 30px">
<button id="startbutton" class="recommend" data-l10n-id="restart">Start</button>
</section>
</section>我做错什么了吗?欢迎任何评论!谢谢。
发布于 2015-05-27 10:08:59
下面是一个使用l10n.js:https://github.com/tuxor1337/fxos-l10n-demo的演示应用程序
请注意,HTML的<head>部分包含有关可用区域设置的信息:
<link rel="localization" href="locales/testing.{locale}.properties" />
<meta name="availableLanguages" content="en-US" />此外,我们不仅包括l10n.js,而且还包括JavaScript的Promise,因为这是l10n.js需要的,但它不是FirefoxOS1.3的一部分:
<script src="es6-promise.js" defer></script>
<script src="l10n.js" defer></script>
<script src="app.js" defer></script>我成功地用Firefox模拟器测试了1.3和2.0版本的代码。请注意,l10n.js的实现略有不同。我使用了gaia:https://github.com/mozilla-b2g/gaia/blob/master/shared/js/l10n.js中使用的Mozilla实现
https://stackoverflow.com/questions/30435230
复制相似问题