有没有一种方法可以在javascript中快速抓取翻译后的字符串?
例如: var s= L20n.get("hello");
我使用的是npm的3.5。
以下内容不起作用:
document.l10n.ready.then(function(context) {
document.l10n.formatValue('myItemKey').then(function(result){
console.log(result);
});
});它会导致打印项目键而不是翻译值。
发布于 2016-05-09 23:40:01
如果您使用的是版本3.x,请使用formatValue
document.l10n.formatValue('hello').then(console.log);你可以在这里阅读更多关于它的内容:https://github.com/l20n/l20n.js/blob/v3.x/docs/view.md#viewformatvalueid-args。document.l10n是View类的一个实例,它在页面加载时自动为您创建。
该方法是异步的,因此您不必担心与尚未加载的语言文件相关的竞争条件。
https://stackoverflow.com/questions/37048083
复制相似问题