国际化使用“国际化内容”在Google Chrome中 [英] Internationalization using "i18n-content" in Google Chrome

查看:304
本文介绍了国际化使用“国际化内容”在Google Chrome中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档建议检索国际化字符串,如下所示:

  document.querySelector(#appname)。innerHTML = chrome.i18n.getMessage(appname); 

但是,内置页面的源代码(如新标签页和内置页面)标签设置页面(示例 here )使用另一种不需要设置额外JavaScript命令的方法:

 < title i18n-content =appname>< / title> 

我试图在自己的Web应用程序和扩展中使用它,但我无法让它发挥作用。

任何人都可以从中看到这一点吗?是否有可能在Web应用程序和扩展中使用它?



更新:我已经标记了穆罕默德曼苏尔的回应,因为从技术上讲,正确。如果有人在寻找基于JavaScript的解决方案,我已经在下面发布了自己的答案。 不同的东西。我将简要解释一下。



对于第一个链接,它指的是Google Chrome扩展API。如果您制作Chrome扩展程序,那么您可以使用其内部化支持API来完成此操作。对于Chrome浏览器中的扩展程序,这是仅限。


$ b 对于第二个链接,它指的是Chrome浏览器内的DOMUI。这是专门为谷歌浏览器!当我们为谷歌浏览器创建选项页面(chrome:// options /)时,我们需要支持多种国际化,而在谷歌浏览器中,所有这些都是用C ++完成的。由于DOMUI页面与Chrome浏览器UI和Core交互,我们从DOMUI(选项页面)和C ++(浏览器)发回消息。此实施方案专门用于Google Chrome内部。



摘要
$ b


  1. 您无法使用上述在普通Web应用程序中提到的方法。他们不是为此而制造的。那里有很多图书馆(如果你是谷歌搜索)支持JavaScript内部化。想到的就是Closure Library。

  2. 对于扩展,请使用上面提到的Chrome扩展的文档。

  3. 对于想要实现带内化支持的DOMUI的C ++应用程序,免费从Chromium复制一些代码,并在您自己的项目中使用它。

我希望能够清除一切。


The official documentation recommends retrieving strings for internationalization like so:

document.querySelector("#appname").innerHTML = chrome.i18n.getMessage("appname");

However, the source code for the built-in pages such as the new tab page and the in-tab settings page (an example here) use a different method which doesn't require setting up additional JavaScript commands:

<title i18n-content="appname"></title> 

I've tried to use this in my own web applications and extensions, but I can't seem to get it to work.

Can anybody shed some light on this? Is it possible to use this in web applications and extensions?

UPDATE: I've marked Mohamd Mansour's response as accepted, because technically it is correct. If anyone were looking for JavaScript-based solution, I've posted my own answer below.

解决方案

You are looking at two completely different stuff. I will briefly explain.

For the first link, it is referring to Google Chrome Extensions API. If your making a Chrome extension, then you can use its internalization support API to do that. That is "only" for Extensions in Google Chrome.

For the second link, it is referring to the DOMUI within Google Chrome the browser. That is specifically made for Google Chrome! When we create Options page for Google Chrome (chrome://options/), we need to support multiple internationalizations, and in Google Chrome, all that is done in C++. Since the DOMUI pages interact with Chrome Browser UI and Core, we send messages back from the DOMUI (options page), and C++ (Browser). This implementation is specifically for Google Chrome internal.

Summarize

  1. You cannot use either approach you mentioned above in a normal Web Application. They are not made for that. There are many libraries out there (if you Google search) for JavaScript internalization support. One that comes to mind is the Closure Library.
  2. For extensions, use the documentation you mentioned above for Chrome Extensions.
  3. For C++ applications that you want to implement a DOMUI with internalization support, feel free to copy some code from Chromium and use it in your own projects.

I hope that cleared things up.

这篇关于国际化使用“国际化内容”在Google Chrome中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆