INNER CODE UNIT · JavaScript

messageListener

mozilla/firefox-translations · extension/controller/backgroundScript.js:135

const messageListener = function(message, sender) {
  // eslint-disable-next-line complexity,max-lines-per-function
    Sentry.wrap(async() => {
      switch (message.command) {
        case "detectPageLanguage": {
          await modelFastTextReadyPromise;

          /*
           * call fasttext to detect the language of the snippet
           * extracted from the page
           */
          const cleanedWords = message.languageDetection.wordsToDetect
            .toLowerCase()
            .trim()
            .replace(/(\r\n|\n|\r)/gm, " ");
          const [score, ftLanguage] = modelFastText
            .predict(cleanedWords, 1, 0.0)
            .get(0);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…