Last active
August 18, 2016 20:03
-
-
Save freaktechnik/74c4b02f5266adedf1a6 to your computer and use it in GitHub Desktop.
the l10n get function for content scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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