Index: gc_core/js/helpers.js ================================================================== --- gc_core/js/helpers.js +++ gc_core/js/helpers.js @@ -1,22 +1,23 @@ // HELPERS "use strict"; +let funcOutput = null; + const helpers = { // In Firefox, there is no console.log in PromiseWorker, but there is worker.log. // In Thunderbird, you can’t access to console directly. So it’s required to pass a log function. - _funcOutput: null, setLogOutput: function (func) { - this._funcOutput = func; + funcOutput = func; }, echo: function (obj) { - if (this._funcOutput !== null) { - this._funcOutput(obj); + if (funcOutput !== null) { + funcOutput(obj); } else { console.log(obj); } return true; }, @@ -24,12 +25,12 @@ logerror: function (e, bStack=false) { let sMsg = "\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message; if (bStack) { sMsg += "\n--- Stack ---\n" + e.stack; } - if (this._funcOutput !== null) { - this._funcOutput(sMsg); + if (funcOutput !== null) { + funcOutput(sMsg); } else { console.error(sMsg); } }, Index: gc_lang/fr/build.py ================================================================== --- gc_lang/fr/build.py +++ gc_lang/fr/build.py @@ -7,13 +7,13 @@ import helpers def build (sLang, dVars, spLangPack): "complementary build launched from make.py" - #createFirefoxExtension(sLang, dVars) + createFirefoxExtension(sLang, dVars) createWebExtension(sLang, dVars) - #createThunderbirdExtension(sLang, dVars, spLangPack) + createThunderbirdExtension(sLang, dVars, spLangPack) def createWebExtension (sLang, dVars): "create Web-extension" print("Building Web-extension") Index: gc_lang/fr/config.ini ================================================================== --- gc_lang/fr/config.ini +++ gc_lang/fr/config.ini @@ -3,11 +3,11 @@ lang_name = French locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_MC fr_BF fr_CI fr_SN fr_ML fr_NE fr_TG fr_BJ country_default = FR name = Grammalecte implname = grammalecte -version = 0.5.17.2 +version = 0.6.0 author = Olivier R. provider = Dicollecte link = http://grammalecte.net description = Correcteur grammatical pour le français. extras = README_fr.txt Index: gc_lang/fr/modules-js/conj.js ================================================================== --- gc_lang/fr/modules-js/conj.js +++ gc_lang/fr/modules-js/conj.js @@ -4,185 +4,173 @@ "use strict"; ${map} -let helpers = null; // module not loaded in Firefox content script - -let _oData = {}; -let _lVtyp = null; -let _lTags = null; -let _dPatternConj = {}; -let _dVerb = {}; - - -if (typeof(exports) !== 'undefined') { - // used within Grammalecte library - helpers = require("resource://grammalecte/helpers.js"); - _oData = JSON.parse(helpers.loadFile("resource://grammalecte/fr/conj_data.json")); - _lVtyp = _oData.lVtyp; - _lTags = _oData.lTags; - _dPatternConj = _oData.dPatternConj; - _dVerb = _oData.dVerb; -} else { - // used within Firefox content script (conjugation panel). - // can’t load JSON from here, so we do it in ui.js and send it here. - self.port.on("provideConjData", function (sData) { - _oData = JSON.parse(sData); - _lVtyp = _oData.lVtyp; - _lTags = _oData.lTags; - _dPatternConj = _oData.dPatternConj; - _dVerb = _oData.dVerb; - }); -} - - -const _zStartVoy = new RegExp("^[aeéiouœê]"); -const _zNeedTeuph = new RegExp("[tdc]$"); - -const _dProSuj = new Map ([ [":1s", "je"], [":1ś", "je"], [":2s", "tu"], [":3s", "il"], [":1p", "nous"], [":2p", "vous"], [":3p", "ils"] ]); -const _dProObj = new Map ([ [":1s", "me "], [":1ś", "me "], [":2s", "te "], [":3s", "se "], [":1p", "nous "], [":2p", "vous "], [":3p", "se "] ]); -const _dProObjEl = new Map ([ [":1s", "m’"], [":1ś", "m’"], [":2s", "t’"], [":3s", "s’"], [":1p", "nous "], [":2p", "vous "], [":3p", "s’"] ]); -const _dImpePro = new Map ([ [":2s", "-toi"], [":1p", "-nous"], [":2p", "-vous"] ]); -const _dImpeProNeg = new Map ([ [":2s", "ne te "], [":1p", "ne nous "], [":2p", "ne vous "] ]); -const _dImpeProEn = new Map ([ [":2s", "-t’en"], [":1p", "-nous-en"], [":2p", "-vous-en"] ]); -const _dImpeProNegEn = new Map ([ [":2s", "ne t’en "], [":1p", "ne nous en "], [":2p", "ne vous en "] ]); - -const _dGroup = new Map ([ ["0", "auxiliaire"], ["1", "1ᵉʳ groupe"], ["2", "2ᵉ groupe"], ["3", "3ᵉ groupe"] ]); - -const _dTenseIdx = new Map ([ [":PQ", 0], [":Ip", 1], [":Iq", 2], [":Is", 3], [":If", 4], [":K", 5], [":Sp", 6], [":Sq", 7], [":E", 8] ]); - - -function isVerb (sVerb) { - return _dVerb.hasOwnProperty(sVerb); -} - -function getConj (sVerb, sTense, sWho) { - // returns conjugation (can be an empty string) - if (!_dVerb.hasOwnProperty(sVerb)) { - return null; - } - if (!_dPatternConj[sTense][_lTags[_dVerb[sVerb][1]][_dTenseIdx.get(sTense)]].hasOwnProperty(sWho)) { - return ""; - } - return _modifyStringWithSuffixCode(sVerb, _dPatternConj[sTense][_lTags[_dVerb[sVerb][1]][_dTenseIdx.get(sTense)]][sWho]); -} - -function hasConj (sVerb, sTense, sWho) { - // returns false if no conjugation (also if empty) else true - if (!_dVerb.hasOwnProperty(sVerb)) { - return false; - } - if (_dPatternConj[sTense][_lTags[_dVerb[sVerb][1]][_dTenseIdx.get(sTense)]].hasOwnProperty(sWho) - && _dPatternConj[sTense][_lTags[_dVerb[sVerb][1]][_dTenseIdx.get(sTense)]][sWho]) { - return true; - } - return false; -} - -function getVtyp (sVerb) { - // returns raw informations about sVerb - if (!_dVerb.hasOwnProperty(sVerb)) { - return null; - } - return _lVtyp[_dVerb[sVerb][0]]; -} - -function getSimil (sWord, sMorph, sFilter=null) { - if (!sMorph.includes(":V")) { - return new Set(); - } - let sInfi = sMorph.slice(1, sMorph.indexOf(" ")); - let tTags = _getTags(sInfi); - let aSugg = new Set(); - if (sMorph.includes(":Q") || sMorph.includes(":Y")) { - // we suggest conjugated forms - if (sMorph.includes(":V1")) { - aSugg.add(sInfi); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":2p")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":1s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Iq", ":3p")); - } else if (sMorph.includes(":V2")) { - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - } else if (sMorph.includes(":V3")) { - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":1s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Ip", ":3s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":1s")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":Is", ":3s")); - } else if (isMorph.includes(":V0a")) { - aSugg.add("eus"); - aSugg.add("eut"); - } else { - aSugg.add("étais"); - aSugg.add("était"); - } - aSugg.delete(""); - } else { - // we suggest past participles - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q1")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q2")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q3")); - aSugg.add(_getConjWithTags(sInfi, tTags, ":PQ", ":Q4")); - aSugg.delete(""); - // if there is only one past participle (epi inv), unreliable. - if (aSugg.size === 1) { - aSugg.clear(); - } - if (sMorph.includes(":V1")) { - aSugg.add(sInfi); - } - } - return aSugg; -} - - -function _getTags (sVerb) { - // returns tuple of tags (usable with functions _getConjWithTags and _hasConjWithTags) - if (!_dVerb.hasOwnProperty(sVerb)) { - return null; - } - return _lTags[_dVerb[sVerb][1]]; -} - -function _getConjWithTags (sVerb, tTags, sTense, sWho) { - // returns conjugation (can be an empty string) - if (!_dPatternConj[sTense][tTags[_dTenseIdx.get(sTense)]].hasOwnProperty(sWho)) { - return ""; - } - return _modifyStringWithSuffixCode(sVerb, _dPatternConj[sTense][tTags[_dTenseIdx.get(sTense)]][sWho]); -} - -function _hasConjWithTags (tTags, sTense, sWho) { - // returns false if no conjugation (also if empty) else true - if (_dPatternConj[sTense][tTags[_dTenseIdx.get(sTense)]].hasOwnProperty(sWho) - && _dPatternConj[sTense][tTags[_dTenseIdx.get(sTense)]][sWho]) { - return true; - } - return false; -} - -function _modifyStringWithSuffixCode (sWord, sSfx) { - // returns sWord modified by sSfx - if (sSfx === "") { - return ""; - } - if (sSfx === "0") { - return sWord; - } - try { - if (sSfx[0] !== '0') { - return sWord.slice(0, -(sSfx.charCodeAt(0)-48)) + sSfx.slice(1); // 48 is the ASCII code for "0" - } else { - return sWord + sSfx.slice(1); - } - } - catch (e) { - console.log(e); - return "## erreur, code : " + sSfx + " ##"; +const conj = { + _lVtyp: null, + _lTags: null, + _dPatternConj: {}, + _dVerb: {}, + + init: function (sJSONData) { + try { + let _oData = JSON.parse(sJSONData); + this._lVtyp = _oData.lVtyp; + this._lTags = _oData.lTags; + this._dPatternConj = _oData.dPatternConj; + this._dVerb = _oData.dVerb; + } + catch (e) { + console.error(e); + } + }, + + _zStartVoy: new RegExp("^[aeéiouœê]"), + _zNeedTeuph: new RegExp("[tdc]$"), + + _dProSuj: new Map ([ [":1s", "je"], [":1ś", "je"], [":2s", "tu"], [":3s", "il"], [":1p", "nous"], [":2p", "vous"], [":3p", "ils"] ]), + _dProObj: new Map ([ [":1s", "me "], [":1ś", "me "], [":2s", "te "], [":3s", "se "], [":1p", "nous "], [":2p", "vous "], [":3p", "se "] ]), + _dProObjEl: new Map ([ [":1s", "m’"], [":1ś", "m’"], [":2s", "t’"], [":3s", "s’"], [":1p", "nous "], [":2p", "vous "], [":3p", "s’"] ]), + _dImpePro: new Map ([ [":2s", "-toi"], [":1p", "-nous"], [":2p", "-vous"] ]), + _dImpeProNeg: new Map ([ [":2s", "ne te "], [":1p", "ne nous "], [":2p", "ne vous "] ]), + _dImpeProEn: new Map ([ [":2s", "-t’en"], [":1p", "-nous-en"], [":2p", "-vous-en"] ]), + _dImpeProNegEn: new Map ([ [":2s", "ne t’en "], [":1p", "ne nous en "], [":2p", "ne vous en "] ]), + + _dGroup: new Map ([ ["0", "auxiliaire"], ["1", "1ᵉʳ groupe"], ["2", "2ᵉ groupe"], ["3", "3ᵉ groupe"] ]), + + _dTenseIdx: new Map ([ [":PQ", 0], [":Ip", 1], [":Iq", 2], [":Is", 3], [":If", 4], [":K", 5], [":Sp", 6], [":Sq", 7], [":E", 8] ]), + + isVerb: function (sVerb) { + return this._dVerb.hasOwnProperty(sVerb); + }, + + getConj: function (sVerb, sTense, sWho) { + // returns conjugation (can be an empty string) + if (!this._dVerb.hasOwnProperty(sVerb)) { + return null; + } + if (!this._dPatternConj[sTense][this._lTags[this._dVerb[sVerb][1]][this._dTenseIdx.get(sTense)]].hasOwnProperty(sWho)) { + return ""; + } + return this._modifyStringWithSuffixCode(sVerb, this._dPatternConj[sTense][this._lTags[this._dVerb[sVerb][1]][this._dTenseIdx.get(sTense)]][sWho]); + }, + + hasConj: function (sVerb, sTense, sWho) { + // returns false if no conjugation (also if empty) else true + if (!this._dVerb.hasOwnProperty(sVerb)) { + return false; + } + if (this._dPatternConj[sTense][this._lTags[this._dVerb[sVerb][1]][this._dTenseIdx.get(sTense)]].hasOwnProperty(sWho) + && this._dPatternConj[sTense][this._lTags[this._dVerb[sVerb][1]][this._dTenseIdx.get(sTense)]][sWho]) { + return true; + } + return false; + }, + + getVtyp: function (sVerb) { + // returns raw informations about sVerb + if (!this._dVerb.hasOwnProperty(sVerb)) { + return null; + } + return this._lVtyp[this._dVerb[sVerb][0]]; + }, + + getSimil: function (sWord, sMorph, sFilter=null) { + if (!sMorph.includes(":V")) { + return new Set(); + } + let sInfi = sMorph.slice(1, sMorph.indexOf(" ")); + let tTags = this._getTags(sInfi); + let aSugg = new Set(); + if (sMorph.includes(":Q") || sMorph.includes(":Y")) { + // we suggest conjugated forms + if (sMorph.includes(":V1")) { + aSugg.add(sInfi); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":2p")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Iq", ":3p")); + } else if (sMorph.includes(":V2")) { + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + } else if (sMorph.includes(":V3")) { + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Ip", ":3s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":1s")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":Is", ":3s")); + } else if (isMorph.includes(":V0a")) { + aSugg.add("eus"); + aSugg.add("eut"); + } else { + aSugg.add("étais"); + aSugg.add("était"); + } + aSugg.delete(""); + } else { + // we suggest past participles + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q1")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q2")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q3")); + aSugg.add(this._getConjWithTags(sInfi, tTags, ":PQ", ":Q4")); + aSugg.delete(""); + // if there is only one past participle (epi inv), unreliable. + if (aSugg.size === 1) { + aSugg.clear(); + } + if (sMorph.includes(":V1")) { + aSugg.add(sInfi); + } + } + return aSugg; + }, + + _getTags: function (sVerb) { + // returns tuple of tags (usable with functions _getConjWithTags and _hasConjWithTags) + if (!this._dVerb.hasOwnProperty(sVerb)) { + return null; + } + return this._lTags[this._dVerb[sVerb][1]]; + }, + + _getConjWithTags: function (sVerb, tTags, sTense, sWho) { + // returns conjugation (can be an empty string) + if (!this._dPatternConj[sTense][tTags[this._dTenseIdx.get(sTense)]].hasOwnProperty(sWho)) { + return ""; + } + return this._modifyStringWithSuffixCode(sVerb, this._dPatternConj[sTense][tTags[this._dTenseIdx.get(sTense)]][sWho]); + }, + + _hasConjWithTags: function (tTags, sTense, sWho) { + // returns false if no conjugation (also if empty) else true + if (this._dPatternConj[sTense][tTags[this._dTenseIdx.get(sTense)]].hasOwnProperty(sWho) + && this._dPatternConj[sTense][tTags[this._dTenseIdx.get(sTense)]][sWho]) { + return true; + } + return false; + }, + + _modifyStringWithSuffixCode: function (sWord, sSfx) { + // returns sWord modified by sSfx + if (sSfx === "") { + return ""; + } + if (sSfx === "0") { + return sWord; + } + try { + if (sSfx[0] !== '0') { + return sWord.slice(0, -(sSfx.charCodeAt(0)-48)) + sSfx.slice(1); // 48 is the ASCII code for "0" + } else { + return sWord + sSfx.slice(1); + } + } + catch (e) { + console.log(e); + return "## erreur, code : " + sSfx + " ##"; + } } } class Verb { @@ -191,107 +179,107 @@ if (typeof sVerb !== "string" || sVerb === "") { throw new TypeError ("The value should be a non-empty string"); } this.sVerb = sVerb; this.sVerbAux = ""; - this._sRawInfo = getVtyp(this.sVerb); + this._sRawInfo = conj.getVtyp(this.sVerb); this.sInfo = this._readableInfo(this._sRawInfo); - this._tTags = _getTags(sVerb); - this._tTagsAux = _getTags(this.sVerbAux); + this._tTags = conj._getTags(sVerb); + this._tTagsAux = conj._getTags(this.sVerbAux); this.bProWithEn = (this._sRawInfo[5] === "e"); this.dConj = new Map ([ [":Y", new Map ([ ["label", "Infinitif"], [":Y", sVerb] ])], [":PQ", new Map ([ ["label", "Participes passés et présent"], - [":Q1", _getConjWithTags(sVerb, this._tTags, ":PQ", ":Q1")], - [":Q2", _getConjWithTags(sVerb, this._tTags, ":PQ", ":Q2")], - [":Q3", _getConjWithTags(sVerb, this._tTags, ":PQ", ":Q3")], - [":Q4", _getConjWithTags(sVerb, this._tTags, ":PQ", ":Q4")], - [":P", _getConjWithTags(sVerb, this._tTags, ":PQ", ":P")] + [":Q1", conj._getConjWithTags(sVerb, this._tTags, ":PQ", ":Q1")], + [":Q2", conj._getConjWithTags(sVerb, this._tTags, ":PQ", ":Q2")], + [":Q3", conj._getConjWithTags(sVerb, this._tTags, ":PQ", ":Q3")], + [":Q4", conj._getConjWithTags(sVerb, this._tTags, ":PQ", ":Q4")], + [":P", conj._getConjWithTags(sVerb, this._tTags, ":PQ", ":P")] ])], [":Ip", new Map ([ ["label", "Présent"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":Ip", ":1s")], - [":1ś", _getConjWithTags(sVerb, this._tTags, ":Ip", ":1ś")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":Ip", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":Ip", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":Ip", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":Ip", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":Ip", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":1s")], + [":1ś", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":1ś")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":Ip", ":3p")] ])], [":Iq", new Map ([ ["label", "Imparfait"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":Iq", ":1s")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":Iq", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":Iq", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":Iq", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":Iq", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":Iq", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":1s")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":Iq", ":3p")] ])], [":Is", new Map ([ ["label", "Passé simple"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":Is", ":1s")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":Is", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":Is", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":Is", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":Is", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":Is", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":1s")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":Is", ":3p")] ])], [":If", new Map ([ ["label", "Futur"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":If", ":1s")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":If", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":If", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":If", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":If", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":If", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":If", ":1s")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":If", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":If", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":If", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":If", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":If", ":3p")] ])], [":Sp", new Map ([ ["label", "Présent subjonctif"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":Sp", ":1s")], - [":1ś", _getConjWithTags(sVerb, this._tTags, ":Sp", ":1ś")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":Sp", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":Sp", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":Sp", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":Sp", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":Sp", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":1s")], + [":1ś", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":1ś")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":Sp", ":3p")] ])], [":Sq", new Map ([ ["label", "Imparfait subjonctif"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":Sq", ":1s")], - [":1ś", _getConjWithTags(sVerb, this._tTags, ":Sq", ":1ś")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":Sq", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":Sq", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":Sq", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":Sq", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":Sq", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":1s")], + [":1ś", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":1ś")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":Sq", ":3p")] ])], [":K", new Map ([ ["label", "Conditionnel"], - [":1s", _getConjWithTags(sVerb, this._tTags, ":K", ":1s")], - [":2s", _getConjWithTags(sVerb, this._tTags, ":K", ":2s")], - [":3s", _getConjWithTags(sVerb, this._tTags, ":K", ":3s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":K", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":K", ":2p")], - [":3p", _getConjWithTags(sVerb, this._tTags, ":K", ":3p")] + [":1s", conj._getConjWithTags(sVerb, this._tTags, ":K", ":1s")], + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":K", ":2s")], + [":3s", conj._getConjWithTags(sVerb, this._tTags, ":K", ":3s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":K", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":K", ":2p")], + [":3p", conj._getConjWithTags(sVerb, this._tTags, ":K", ":3p")] ])], [":E", new Map ([ ["label", "Impératif"], - [":2s", _getConjWithTags(sVerb, this._tTags, ":E", ":2s")], - [":1p", _getConjWithTags(sVerb, this._tTags, ":E", ":1p")], - [":2p", _getConjWithTags(sVerb, this._tTags, ":E", ":2p")] + [":2s", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2s")], + [":1p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":1p")], + [":2p", conj._getConjWithTags(sVerb, this._tTags, ":E", ":2p")] ])] ]); }; _readableInfo () { // returns readable infos this.sVerbAux = (this._sRawInfo.slice(7,8) == "e") ? "être" : "avoir"; - let sGroup = _dGroup.get(this._sRawInfo[0]); + let sGroup = conj._dGroup.get(this._sRawInfo[0]); let sInfo = ""; if (this._sRawInfo.slice(3,4) == "t") { sInfo = "transitif"; } else if (this._sRawInfo.slice(4,5) == "n") { sInfo = "transitif indirect"; @@ -323,11 +311,11 @@ } if (bPro) { if (this.bProWithEn) { sInfi = "s’en " + sInfi; } else { - sInfi = (_zStartVoy.test(sInfi)) ? "s’" + sInfi : "se " + sInfi; + sInfi = (conj._zStartVoy.test(sInfi)) ? "s’" + sInfi : "se " + sInfi; } } if (bNeg) { sInfi = "ne pas " + sInfi; } @@ -348,18 +336,18 @@ if (!this.dConj.get(":PQ").get(":P")) { return ""; } let sPartPre; if (bTpsCo) { - sPartPre = (!bPro) ? _getConjWithTags(this.sVerbAux, this._tTagsAux, ":PQ", ":P") : getConj("être", ":PQ", ":P"); + sPartPre = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, ":PQ", ":P") : getConj("être", ":PQ", ":P"); } else { sPartPre = this.dConj.get(":PQ").get(":P"); } if (sPartPre === "") { return ""; } - let bEli = _zStartVoy.test(sPartPre); + let bEli = conj._zStartVoy.test(sPartPre); if (bPro) { if (this.bProWithEn) { sPartPre = "s’en " + sPartPre; } else { sPartPre = (bEli) ? "s’" + sPartPre : "se " + sPartPre; @@ -384,30 +372,30 @@ let sConj; if (!bTpsCo && bInt && sWho == ":1s" && this.dConj.get(sTemps)._get(":1ś", false)) { sWho = ":1ś"; } if (bTpsCo) { - sConj = (!bPro) ? _getConjWithTags(this.sVerbAux, this._tTagsAux, sTemps, sWho) : getConj("être", sTemps, sWho); + sConj = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, sTemps, sWho) : getConj("être", sTemps, sWho); } else { sConj = this.dConj.get(sTemps).get(sWho); } if (sConj === "") { return ""; } - let bEli = _zStartVoy.test(sConj); + let bEli = conj._zStartVoy.test(sConj); if (bPro) { if (!this.bProWithEn) { - sConj = (bEli) ? _dProObjEl.get(sWho) + sConj : _dProObj.get(sWho) + sConj; + sConj = (bEli) ? conj._dProObjEl.get(sWho) + sConj : conj._dProObj.get(sWho) + sConj; } else { - sConj = _dProObjEl.get(sWho) + "en " + sConj; + sConj = conj._dProObjEl.get(sWho) + "en " + sConj; } } if (bNeg) { sConj = (bEli && !bPro) ? "n’" + sConj : "ne " + sConj; } if (bInt) { - if (sWho == ":3s" && !_zNeedTeuph.test(sConj)) { + if (sWho == ":3s" && !conj._zNeedTeuph.test(sConj)) { sConj += "-t"; } sConj += "-" + this._getPronom(sWho, bFem); } else { if (sWho == ":1s" && bEli && !bNeg && !bPro) { @@ -436,39 +424,39 @@ return "elle"; } } else if (sWho == ":3p" && bFem) { return "elles"; } - return _dProSuj.get(sWho); + return conj._dProSuj.get(sWho); }; imperatif (sWho, bPro, bNeg, bTpsCo, bFem) { if (!this.dConj.get(":E").get(sWho)) { return ""; } let sImpe; if (bTpsCo) { - sImpe = (!bPro) ? _getConjWithTags(this.sVerbAux, this._tTagsAux, ":E", sWho) : getConj("être", ":E", sWho); + sImpe = (!bPro) ? conj._getConjWithTags(this.sVerbAux, this._tTagsAux, ":E", sWho) : getConj("être", ":E", sWho); } else { sImpe = this.dConj.get(":E").get(sWho); } if (sImpe === "") { return ""; } - let bEli = _zStartVoy.test(sImpe); + let bEli = conj._zStartVoy.test(sImpe); if (bNeg) { if (bPro) { if (!this.bProWithEn) { - sImpe = (bEli && sWho == ":2s") ? "ne t’" + sImpe + " pas" : _dImpeProNeg.get(sWho) + sImpe + " pas"; + sImpe = (bEli && sWho == ":2s") ? "ne t’" + sImpe + " pas" : conj._dImpeProNeg.get(sWho) + sImpe + " pas"; } else { - sImpe = _dImpeProNegEn.get(sWho) + sImpe + " pas"; + sImpe = conj._dImpeProNegEn.get(sWho) + sImpe + " pas"; } } else { sImpe = (bEli) ? "n’" + sImpe + " pas" : "ne " + sImpe + " pas"; } } else if (bPro) { - sImpe = (this.bProWithEn) ? sImpe + _dImpeProEn.get(sWho) : sImpe + _dImpePro.get(sWho); + sImpe = (this.bProWithEn) ? sImpe + conj._dImpeProEn.get(sWho) : sImpe + conj._dImpePro.get(sWho); } if (bTpsCo) { return sImpe + " " + this._seekPpas(bPro, bFem, sWho.endsWith("p") || this._sRawInfo[5] == "r"); } return sImpe; @@ -488,17 +476,28 @@ } } if (typeof(exports) !== 'undefined') { - // Used for Grammalecte library. - // In content scripts, these variable are directly reachable + // used within Grammalecte library + let helpers = require("resource://grammalecte/helpers.js"); + conj.init(helpers.loadFile("resource://grammalecte/fr/conj_data.json")); +} else { + // used within Firefox content script (conjugation panel). + // can’t load JSON from here, so we do it in ui.js and send it here. + self.port.on("provideConjData", function (sJSONData) { + conj.init(sJSONData); + }); +} + + +if (typeof(exports) !== 'undefined') { exports.Verb = Verb; - exports.isVerb = isVerb; - exports.getConj = getConj; - exports.hasConj = hasConj; - exports.getVtyp = getVtyp; - exports.getSimil = getSimil; - exports._getTags = _getTags; - exports._hasConjWithTags = _hasConjWithTags; - exports._getConjWithTags = _getConjWithTags; + exports.isVerb = conj.isVerb; + exports.getConj = conj.getConj; + exports.hasConj = conj.hasConj; + exports.getVtyp = conj.getVtyp; + exports.getSimil = conj.getSimil; + exports._getTags = conj._getTags; + exports._hasConjWithTags = conj._hasConjWithTags; + exports._getConjWithTags = conj._getConjWithTags; } Index: gc_lang/fr/xpi/data/conj_panel.js ================================================================== --- gc_lang/fr/xpi/data/conj_panel.js +++ gc_lang/fr/xpi/data/conj_panel.js @@ -69,11 +69,11 @@ if (sVerb.endsWith("?")) { document.getElementById('oint').checked = true; sVerb = sVerb.slice(0,-1).trim(); } - if (!isVerb(sVerb)) { + if (!conj.isVerb(sVerb)) { document.getElementById('verb').style = "color: #BB4411;"; } else { self.port.emit("show"); document.getElementById('verb_title').textContent = sVerb; document.getElementById('verb').style = "color: #999999;"; Index: gc_lang/fr/xpi/package.json ================================================================== --- gc_lang/fr/xpi/package.json +++ gc_lang/fr/xpi/package.json @@ -1,10 +1,10 @@ { "name": "grammalecte-fr", "title": "Grammalecte [fr]", "id": "French-GC@grammalecte.net", - "version": "0.5.17.2", + "version": "0.6.0", "description": "Correcteur grammatical pour le français", "homepage": "http://www.dicollecte.org/grammalecte", "main": "ui.js", "icon": "data/img/icon-48.png", "scripts": {