google-chromeinternationalization

Internationalization using "i18n-content" in Google Chrome


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.


Solution

  • 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.