RequestPolicyContinued / requestpolicy

a web browser extension that gives you control over cross-site requests. Available for XUL/XPCOM-based browsers.
https://github.com/RequestPolicyContinued/requestpolicy/wiki
Other
252 stars 35 forks source link

WE transition: switch locale (i18n) system #873

Closed myrdd closed 6 years ago

myrdd commented 6 years ago

The WE i18n system is described here:

The main function we need is browser.i18n.getMessage() [MDN docs]:

browser.i18n.getMessage(
  messageName,  // string
  substitutions // optional any
)

It will replace StringUtils.$str().

BTW, we do not need Locale-dependent CSS


Since we are going to maintain a XPCOM version of RPC (e.g. for palemoon) we need a browser.i18n.getMessage() fake API. We can take the code from Mozilla (licensed as MPL 2.0, so the copy-pasted code needs to be in a separate file with MPL2.0 header).

I've tracked down the browser.i18n.getMessage() system:

browser.i18n.getMessage()

getMessage: function(messageName, substitutions) {
  return extension.localizeMessage(messageName, substitutions, {cloneScope: context.cloneScope});
},

ExtensionData.localizeMessage()

localizeMessage(...args) {
  return this.localeData.localizeMessage(...args);
}

ExtensionData.localeData

this.localeData = new LocaleData({
  defaultLocale: this.defaultLocale,
  locales,
  builtinMessages: this.builtinMessages,
});

LocaleData.localizeMessage()

localizeMessage(message, substitutions = [], options = {}) {
  // ...
},

Tasks

myrdd commented 6 years ago

Regarding the current localization of the settings pages (XUL / HTML), see this piece of code: https://github.com/RequestPolicyContinued/requestpolicy/blob/5697d0e2d7d8aa56c86fc21bda5cc306e96bc5af/src/content/lib/utils/xul.js#L136-L160

Strings like "&foobar;" are replaced by the string returned by StringUtils.$str("foobar").

jrrdev commented 6 years ago

I can take care of it because I will need it very soon for issue #871

myrdd commented 6 years ago

I've created subtask issue #876: convert *.properties to message.json files

@jrrdev do you think you could take it?

myrdd commented 6 years ago

The first three tasks are done :)

@jrrdev do you have some time to implement browser.i18n.getMessage(), and to change the add-on's code to use that API function?

Please note that we can take browser.i18n.getMessage() fake API code from Mozilla, see the issue's comment / the first comment. (If it helps, you can also use this function: https://github.com/myrdd/requestpolicy/blob/17ff5d586b9974fe2c14999ace2e47169bd5edde/gulpfile.js#L225-L235)

jrrdev commented 6 years ago

Hi, I started to look at Mozilla's code but I didn't have much time last week to look deeper. Fortunately, I have a lot of free time this week :-) I hope to finish the remaining task by the end of the week

myrdd commented 6 years ago

Great! :)

jrrdev commented 6 years ago

@myrdd I have some trouble to implement ExtensionData.readDirectory because I need to fetch the directory contents from chrome://rpcontinued/content/_locales (thus it can't create a nsIFileURL because of scheme chrome://). I found a workaround using xhr and parsing the http response which looks like (I made a test on /content/bootstrap):

300: jar:file:///tmp/tmpC5HhWt.mozrunner/extensions/rpcontinued@non-amo.requestpolicy.org.xpi!/content/bootstrap/
200: filename content-length last-modified file-type
201: bootstrap.jsm 8674 Sun,%2017%20Dec%202017%2020:28:40%20GMT FILE
201: data/ 0 Sat,%2002%20Dec%202017%2019:01:14%20GMT DIRECTORY
201: environments/ 0 Sat,%2002%20Dec%202017%2019:01:14%20GMT DIRECTORY
201: modules/ 0 Sat,%2002%20Dec%202017%2019:01:14%20GMT DIRECTORY

But it seems a little hackish... Do you have some ideas on a better way to proceed with ?

myrdd commented 6 years ago

@jrrdev IMHO you could simply hard-code the list of locales, just like it is done for install.rdf. I've added commit https://github.com/myrdd/requestpolicy/commit/98458930858402297f09eba38966ada88311928f onto https://github.com/myrdd/requestpolicy/tree/feature/we-i18n. Now you can simply use bootstrap/data/locales. :)

jrrdev commented 6 years ago

It is indeed much easier to deal with the hard-coded list :smile: Thank you !

cheggerdev commented 6 years ago

I think this issue can be closed, no?

myrdd commented 6 years ago

true, thanks