Index: gc_core/py/oxt/Linguistic.xcu ================================================================== --- gc_core/py/oxt/Linguistic.xcu +++ gc_core/py/oxt/Linguistic.xcu @@ -6,9 +6,14 @@ ${locales} + + + + ${locales} + Index: gc_core/py/oxt/manifest.xml ================================================================== --- gc_core/py/oxt/manifest.xml +++ gc_core/py/oxt/manifest.xml @@ -14,10 +14,14 @@ + + + Index: gc_lang/fr/config.ini ================================================================== --- gc_lang/fr/config.ini +++ gc_lang/fr/config.ini @@ -1,9 +1,9 @@ [args] lang = fr 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 +locales = fr_FR fr_BE fr_CA fr_CH fr_LU fr_BF fr_BJ fr_CD fr_CI fr_CM fr_MA fr_ML fr_MU fr_NE fr_RE fr_SN fr_TG country_default = FR name = Grammalecte implname = grammalecte # always use 3 numbers for version: x.y.z version = 0.6.3 @@ -77,10 +77,12 @@ oxt/_img/Algoo_logo.png = img/Algoo_logo.png oxt/_img/grammalecte_16.bmp = img/grammalecte_16.bmp oxt/_img/french_flag_16.bmp = img/french_flag_16.bmp # AppLauncher oxt/AppLauncher.py = AppLauncher.py +# Graphspell +oxt/Graphspell.py = Graphspell.py # About oxt/About/About.py = pythonpath/About.py oxt/About/ab_strings.py = pythonpath/ab_strings.py # Dictionaries oxt/Dictionnaires/dictionaries = dictionaries Index: gc_lang/fr/oxt/Dictionnaires/dictionaries.xcu ================================================================== --- gc_lang/fr/oxt/Dictionnaires/dictionaries.xcu +++ gc_lang/fr/oxt/Dictionnaires/dictionaries.xcu @@ -8,11 +8,12 @@ DICT_SPELL - 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 + fr-MC + @@ -21,11 +22,11 @@ DICT_HYPH - 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 + fr-FR fr-BE fr-CA fr-CH fr-LU fr-MC fr-BF fr-BJ fr-CD fr-CI fr-CM fr-MA fr-ML fr-MU fr-NE fr-RE fr-SN fr-TG %origin%/dictionaries/thes_fr.dat %origin%/dictionaries/thes_fr.idx @@ -32,11 +33,11 @@ DICT_THES - 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 + fr-FR fr-BE fr-CA fr-CH fr-LU fr-MC fr-BF fr-BJ fr-CD fr-CI fr-CM fr-MA fr-ML fr-MU fr-NE fr-RE fr-SN fr-TG ADDED gc_lang/fr/oxt/Graphspell.py Index: gc_lang/fr/oxt/Graphspell.py ================================================================== --- gc_lang/fr/oxt/Graphspell.py +++ gc_lang/fr/oxt/Graphspell.py @@ -0,0 +1,159 @@ +# Graphspell +# +# Spellchecker based on a DAWG (Direct Acyclic Word Graph) + + +import uno +import unohelper +import traceback +import re + +from grammalecte.graphspell import SpellChecker + +from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives +from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName +from com.sun.star.lang import Locale + + +lLocale = { + # List of locales in LibreOffice + # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx + ('la', 'VA', ''), # Latin (for testing purpose) + ('fr', 'FR', ''), # France + ('fr', 'BE', ''), # Belgique + ('fr', 'CA', ''), # Canada + ('fr', 'CH', ''), # Suisse + ('fr', 'LU', ''), # Luxembourg + #('fr', 'MC', ''), # Monaco + ('fr', 'BF', ''), # Burkina Faso + ('fr', 'BJ', ''), # Benin + ('fr', 'CD', ''), # Congo + ('fr', 'CI', ''), # Côte d’Ivoire + ('fr', 'CM', ''), # Cameroun + ('fr', 'MA', ''), # Maroc + ('fr', 'ML', ''), # Mali + ('fr', 'MU', ''), # Île Maurice + ('fr', 'NE', ''), # Niger + ('fr', 'RE', ''), # Réunion + ('fr', 'SN', ''), # Sénégal + ('fr', 'TG', '') # Togo +} + +zElidedWords = re.compile("(?i)^(?:[ldnmtsjcçy]|qu|lorsqu|quoiqu|puisqu|jusqu)['’`‘]") + + +class Graphspell (unohelper.Base, XSpellChecker, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales): + + def __init__ (self, ctx, *args): + try: + self.ctx = ctx + self.sServiceName = "com.sun.star.linguistic2.SpellChecker" + self.sImplementationName = "net.grammalecte.graphspell" + self.tSupportedServiceNames = (self.sServiceName, ) + self.xSvMgr = ctx.ServiceManager + self.locales = tuple([ Locale(t[0], t[1], t[2]) for t in lLocale ]) + self.oGraphspell = SpellChecker("fr", "fr.bdic") + self.bHunspell + self.xHunspell = None + self.xHunspellLocale = Locale('fr', 'MC', '') + #self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale') + #self.xHunspellLocale.Language = 'fr' + #self.xHunspellLocale.Country = 'FR' + print("init done") + except: + print("Graphspell: init") + traceback.print_exc() + + # XServiceName + def getServiceName (self): + return self.sImplementationName #self.sServiceName + + # XServiceInfo + def getImplementationName (self): + return self.sImplementationName + + def supportsService (self, sServiceName): + return (sServiceName in self.tSupportedServiceNames) + + def getSupportedServiceNames (self): + return self.tSupportedServiceNames + + # XSupportedLocales + def hasLocale (self, aLocale): + if aLocale in self.locales: + return True + for e in self.locales: + if aLocale.Language == e.Language and (e.Country == aLocale.Country or e.Country == ""): + return True + return False + + def getLocales (self): + return self.locales + + # XSpellChecker + # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html + def isValid (self, aWord, rLocale, aProperties): + try: + aWord = zElidedWords.sub("", aWord.rstrip("."), count=1) + return self.oGraphspell.isValidToken(aWord) + except: + traceback.print_exc() + return False + + def spell (self, aWord, aLocale, aProperties): + "returns an object SpellAlternatives" + lSugg = [] + for l in self.oGraphspell.suggest(aWord): + lSugg.extend(l) + return SpellAlternatives(aWord, tuple(lSugg)) + try: + if not self.xHunspell: + self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker") + if self.xHunspell: + return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties) + except: + traceback.print_exc() + return None + + # XServiceDisplayName + def getServiceDisplayName(self, aLocale): + return "Graphspell (fr)" + + +class SpellAlternatives (unohelper.Base, XSpellAlternatives): + + def __init__ (self, sWord, lSugg): + try: + self.sWord = sWord + self.lSugg = lSugg + self.xLocale = Locale('fr', 'FR', '') + except: + traceback.print_exc() + + # XSpellAlternatives + # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellAlternatives.html + def getWord (self): + return self.sWord + + def getLocale (self): + return self.xLocale + + def getFailureType (self): + return 4 + # IS_NEGATIVE_WORD = 2 + # The word is a negative one, that is, it should not be used. + # CAPTION_ERROR = 3 + # The capitalization of the word is wrong. + # SPELLING_ERROR = 4 + # The spelling of the word is wrong (or at least not known to be correct). + # No difference -> red underline + + def getAlternativesCount (self): + return len(self.lSugg) + + def getAlternatives (self): + return self.lSugg + + +g_ImplementationHelper = unohelper.ImplementationHelper() +g_ImplementationHelper.addImplementation(Graphspell, "net.grammalecte.graphspell", ("com.sun.star.linguistic2.SpellChecker",),) DELETED gc_lang/fr/oxt/Graphspell/Graphspell.py Index: gc_lang/fr/oxt/Graphspell/Graphspell.py ================================================================== --- gc_lang/fr/oxt/Graphspell/Graphspell.py +++ gc_lang/fr/oxt/Graphspell/Graphspell.py @@ -1,159 +0,0 @@ -# Graphspell -# -# Spellchecker based on a DAWG (Direct Acyclic Word Graph) - - -import uno -import unohelper -import traceback -import re - -from grammalecte.graphspell import SpellChecker - -from com.sun.star.linguistic2 import XSupportedLocales, XSpellChecker, XSpellAlternatives -from com.sun.star.lang import XServiceInfo, XServiceName, XServiceDisplayName -from com.sun.star.lang import Locale - - -lLocale = { - # List of locales in LibreOffice - # https://cgit.freedesktop.org/libreoffice/core/tree/i18nlangtag/source/isolang/isolang.cxx - ('la', 'VA', ''), # Latin (for testing purpose) - ('fr', 'FR', ''), # France - ('fr', 'BE', ''), # Belgique - ('fr', 'CA', ''), # Canada - ('fr', 'CH', ''), # Suisse - ('fr', 'LU', ''), # Luxembourg - #('fr', 'MC', ''), # Monaco - ('fr', 'BF', ''), # Burkina Faso - ('fr', 'BJ', ''), # Benin - ('fr', 'CD', ''), # Congo - ('fr', 'CI', ''), # Côte d’Ivoire - ('fr', 'CM', ''), # Cameroun - ('fr', 'MA', ''), # Maroc - ('fr', 'ML', ''), # Mali - ('fr', 'MU', ''), # Île Maurice - ('fr', 'NE', ''), # Niger - ('fr', 'RE', ''), # Réunion - ('fr', 'SN', ''), # Sénégal - ('fr', 'TG', '') # Togo -} - -zElidedWords = re.compile("(?i)^(?:[ldnmtsjcçy]|qu|lorsqu|quoiqu|puisqu|jusqu)['’`‘]") - - -class Graphspell (unohelper.Base, XSpellChecker, XServiceInfo, XServiceName, XServiceDisplayName, XSupportedLocales): - - def __init__ (self, ctx, *args): - try: - self.ctx = ctx - self.sServiceName = "com.sun.star.linguistic2.SpellChecker" - self.sImplementationName = "net.grammalecte.graphspell" - self.tSupportedServiceNames = (self.sServiceName, ) - self.xSvMgr = ctx.ServiceManager - self.locales = tuple([ Locale(t[0], t[1], t[2]) for t in lLocale ]) - self.oGraphspell = SpellChecker("fr", "fr.bdic") - self.bHunspell - self.xHunspell = None - self.xHunspellLocale = Locale('fr', 'MC', '') - #self.xHunspellLocale = uno.createUnoStruct('com.sun.star.lang.Locale') - #self.xHunspellLocale.Language = 'fr' - #self.xHunspellLocale.Country = 'FR' - print("init done") - except: - print("Graphspell: init") - traceback.print_exc() - - # XServiceName - def getServiceName (self): - return self.sImplementationName #self.sServiceName - - # XServiceInfo - def getImplementationName (self): - return self.sImplementationName - - def supportsService (self, sServiceName): - return (sServiceName in self.tSupportedServiceNames) - - def getSupportedServiceNames (self): - return self.tSupportedServiceNames - - # XSupportedLocales - def hasLocale (self, aLocale): - if aLocale in self.locales: - return True - for e in self.locales: - if aLocale.Language == e.Language and (e.Country == aLocale.Country or e.Country == ""): - return True - return False - - def getLocales (self): - return self.locales - - # XSpellChecker - # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellChecker.html - def isValid (self, aWord, rLocale, aProperties): - try: - aWord = zElidedWords.sub("", aWord.rstrip("."), count=1) - return self.oGraphspell.isValidToken(aWord) - except: - traceback.print_exc() - return False - - def spell (self, aWord, aLocale, aProperties): - "returns an object SpellAlternatives" - lSugg = [] - for l in self.oGraphspell.suggest(aWord): - lSugg.extend(l) - return SpellAlternatives(aWord, tuple(lSugg)) - try: - if not self.xHunspell: - self.xHunspell = self.xSvMgr.createInstance("com.sun.star.linguistic2.SpellChecker") - if self.xHunspell: - return self.xHunspell.spell(aWord, self.xHunspellLocale, aProperties) - except: - traceback.print_exc() - return None - - # XServiceDisplayName - def getServiceDisplayName(self, aLocale): - return "Graphspell (fr)" - - -class SpellAlternatives (unohelper.Base, XSpellAlternatives): - - def __init__ (self, sWord, lSugg): - try: - self.sWord = sWord - self.lSugg = lSugg - self.xLocale = Locale('fr', 'FR', '') - except: - traceback.print_exc() - - # XSpellAlternatives - # http://www.openoffice.org/api/docs/common/ref/com/sun/star/linguistic2/XSpellAlternatives.html - def getWord (self): - return self.sWord - - def getLocale (self): - return self.xLocale - - def getFailureType (self): - return 4 - # IS_NEGATIVE_WORD = 2 - # The word is a negative one, that is, it should not be used. - # CAPTION_ERROR = 3 - # The capitalization of the word is wrong. - # SPELLING_ERROR = 4 - # The spelling of the word is wrong (or at least not known to be correct). - # No difference -> red underline - - def getAlternativesCount (self): - return len(self.lSugg) - - def getAlternatives (self): - return self.lSugg - - -g_ImplementationHelper = unohelper.ImplementationHelper() -g_ImplementationHelper.addImplementation(Graphspell, "net.grammalecte.graphspell", ("com.sun.star.linguistic2.SpellChecker",),)