chrome extension localization doesn't allow to select language different from chrome's one

86 views
Skip to first unread message

Lev Mishin

unread,
Oct 30, 2016, 4:12:18 AM10/30/16
to Chromium-Extensions-Announce
if you call method
chrome.i18n.getMessage("some_message")
you will get a translation according to chrome's locale settings

But it would be nice to have an ability to specify lang you want to use for your extension and let user change it in settings
so I propose to add a method to i18n API:
chrome.i18n.setLocale("en")

And if there is no any objections I can try to implement it by myself

PS if it is a wrong thread to post please let me know which one would more appropriate

Lev Mishin

unread,
Oct 30, 2016, 4:14:22 AM10/30/16
to Chromium-Extensions-Announce

Antony Sargent

unread,
Oct 31, 2016, 2:28:27 PM10/31/16
to Lev Mishin, Chromium-Extensions-Announce
Note that you can sort of do this in javascript just by using an XHR to fetch the messages.json file and then parse it yourself. Here's a quick example:

function getMessageForLocale(message, locale, callback) {
  let xhr = new XmlHttpRequest();
  xhr.open("GET", chrome.runtime.getURL("_locales/" + locale + "/messages.json");
  xhr.onload = function() {
    let parsed = JSON.parse(xhr.responseText);
    callback(parsed[message]);
  };
}

You'd want to add some error handling, but that's the essential idea. 




--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/ec2997c9-9da3-4997-960d-2b7a71b5740b%40chromium.org.

Lev Mishin

unread,
Nov 1, 2016, 10:21:29 AM11/1/16
to Antony Sargent, Chromium-Extensions-Announce

Yes, I understand that, but it was easier and more consistent if it would be provided by chrome api. 

Now I use chrome.i18n to localize manifest only and to get browser locale to use it as a default one, structure of messages.json not so convenient to work with it manually.


On Mon, Oct 31, 2016, 7:28 PM Antony Sargent <asar...@chromium.org> wrote:
Note that you can sort of do this in javascript just by using an XHR to fetch the messages.json file and then parse it yourself. Here's a quick example:

function getMessageForLocale(message, locale, callback) {
  let xhr = new XmlHttpRequest();
  xhr.open("GET", chrome.runtime.getURL("_locales/" + locale + "/messages.json");
  xhr.onload = function() {
    let parsed = JSON.parse(xhr.responseText);
    callback(parsed[message]);
  };
}

You'd want to add some error handling, but that's the essential idea. 



On Sun, Oct 30, 2016 at 1:14 AM, Lev Mishin <leomi...@gmail.com> wrote:
Add a link to issue
https://bugs.chromium.org/p/chromium/issues/detail?id=660704#

On Sunday, October 30, 2016 at 9:12:18 AM UTC+1, Lev Mishin wrote:
if you call method
chrome.i18n.getMessage("some_message")
you will get a translation according to chrome's locale settings

But it would be nice to have an ability to specify lang you want to use for your extension and let user change it in settings
so I propose to add a method to i18n API:
chrome.i18n.setLocale("en")

And if there is no any objections I can try to implement it by myself

PS if it is a wrong thread to post please let me know which one would more appropriate

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.

--

Kind regards,
Lev Mishin

Conrado Cocho Torres

unread,
Nov 1, 2016, 12:39:24 PM11/1/16
to Chromium-Extensions-Announce
Reply all
Reply to author
Forward
0 new messages