Skip to content

Instantly share code, notes, and snippets.

@freaktechnik
Last active August 18, 2016 20:03
Show Gist options
  • Save freaktechnik/74c4b02f5266adedf1a6 to your computer and use it in GitHub Desktop.
Save freaktechnik/74c4b02f5266adedf1a6 to your computer and use it in GitHub Desktop.
the l10n get function for content scripts.
function _(id) {
// I'm using self here, but replace it with addon, in case you're loading your content script directly in your html file for a panel
return new Promise((resolve) => {
self.port.once("translated", resolve);
});
self.port.emit("translate", id);
}
// Example usage:
_("anerror").then((string) => {
console.log(string);
});
"use strict";
const { get: _ } = require("sdk/l10n");
const { PageMod } = require("sdk/page-mod");
const pageMod = new PageMod({
// Your page-mod config
});
// Your worker/port thing is saved in pageMod
pageMod.port.on("translate", (id) => {
pageMod.port.emit("translated", _(id));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment