Chrome扩展中的本地化 [英] localization in Chrome extensions
问题描述
我有一个与Chrome扩展的本地化相关的查询。我正在尝试本地化我的扩展程序中弹出式HTML文件中的按钮中的文本。我使用的代码如下:
< button name =buttonSaveid =buttonSavestyle =width :100px; float:right;>
< label class =buttonTextStyle>
< / label>
< / button>
javascript代码如下:
document.getElementById(buttonSave)。innerText = chrome.i18n.getMessage(SaveButton);
我曾尝试使用innerText,innerHTML,但该按钮中的文本未应用。我在这里做错了什么?
我只是使用< input type =button >
并设置按钮的值
属性:
< input type =buttonname =buttonSaveid =buttonSavestyle =width:100px; float:right;>
....
document.getElementById(buttonSave)。value = chrome.i18n.getMessage(SaveButton);
顺便说一句,我相当确定有一个< label>嵌套在
不是有效的HTML。改用< button>
内的< div>
或< span>
。
编辑:
我刚做了一个测试,并使用 .innerHTML
或 .innerText
应该可以正常工作。您确定:
-
chrome.i18n.getMessage(SaveButton)的返回值
非空? (即,
document.getElementById(buttonSave)
不为空或抛出错误)? 另外,要明白覆盖 innerText
或 innerHTML $按钮的c $ c>会破坏已经在按钮内的元素。也许你真的想做
document.querySelector(#buttonSave .buttonTextStyle)。innerText
来编写嵌套在按钮中的元素?
I have a query related to localization of Chrome extensions. I am trying to localize the text in a button in a popup html file in my extension. The code I am using is as follows:
<button name="buttonSave" id="buttonSave" style="width: 100px; float: right;">
<label class="buttonTextStyle">
</label>
</button>
The javascript code is as follows:
document.getElementById("buttonSave").innerText = chrome.i18n.getMessage("SaveButton");
I have tried using innerText, innerHTML, value but the text in the button is not applied. Am I doing something wrong here?
I would just use <input type="button">
and set the value
property of the button:
<input type="button" name="buttonSave" id="buttonSave" style="width: 100px; float: right;">
....
document.getElementById("buttonSave").value = chrome.i18n.getMessage("SaveButton");
By the way, I'm fairly certain having a <label>
nested inside of a <button>
is not valid HTML. Use a <div>
or <span>
instead.
EDIT:
I just did a test, and using either .innerHTML
or .innerText
should work fine. Are you sure that:
the return value of
chrome.i18n.getMessage("SaveButton")
is non-empty?you are running
document.getElementById("buttonSave")
after the DOM is built (i.e.,document.getElementById("buttonSave")
is not null or throwing an error)?
Also, understand that overwriting the innerText
or innerHTML
of the button will destroy the elements you have inside the button already. Perhaps you actually want to do document.querySelector("#buttonSave .buttonTextStyle").innerText
to write the the element nested inside the button?
这篇关于Chrome扩展中的本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!