Salome HOME
pour MT
[tools/eficas.git] / Extensions / localisation.py
index 0de1f72ebe478edc22d14e2e9438a5492ce1ec86..ff906ca218c757c1ff22d6f20efb42c01e0764d5 100644 (file)
 # You should have received a copy of the GNU Lesser General Public License along
 # with this program. If not, see <http://www.gnu.org/licenses/>.
 """
-Creates and loads two ``QTranslator`` objects, one for pure Qt, one for Eficas,
-and installs them to a ``QApplication``.
 
 """
 
+from __future__ import absolute_import
+from __future__ import print_function
 import os
-from determine import monEnvQT5
-if monEnvQT5 :
-   from PyQt5.QtCore import QTranslator
-else :
-   from PyQt4.QtCore import QTranslator
 
-qt_translator = QTranslator()
+from PyQt5.QtCore import QTranslator
+
+code_translator = QTranslator()
 eficas_translator = QTranslator()
 
-def localise(application, locale=None ):
+def localise(application, locale=None,file=None,translatorFichier=None, debug=False ):
     """
-    localise(QApplication) -> None
-
-    Loads and installs to a ``QApplication`` two ``QTranslator``
-    objects, one for pure Qt for translating the strings 
-    available in Qt, and one or Eficas, for translating 
-    the strings specified precisely for Eficas.
-    If the Qt base translator cannot be loaded with the locale
-    specified by the user, one attempts to load Qt base 
-    translator with the system locale.
-    If no locale is specified by the user, the system locale
-    is used instead, for both Qt base and Eficas translators.
     """
-    if monEnvQT5 :
-       from PyQt5.QtCore import QLibraryInfo
-       from PyQt5.QtCore import QLocale
-       from PyQt5.QtWidgets import QApplication
-       monPath=os.path.join(os.path.dirname(__file__),'..','UiQT5')
-    else :
-       from PyQt4.QtCore import QLibraryInfo
-       from PyQt4.QtCore import QLocale
-       from PyQt4.QtGui import QApplication
-       monPath=os.path.join(os.path.dirname(__file__),'..','UiQT4')
+    from PyQt5.QtCore import QLibraryInfo
+    from PyQt5.QtCore import QLocale
+    from PyQt5.QtWidgets import QApplication
+    monPath=os.path.join(os.path.dirname(__file__),'..','UiQT5')
 
     sys_locale = QLocale.system().name()
 
-    if locale is None:
-        #locale = sys_locale
-        locale="fr"
-
-    #global qt_translator
-    #if qt_translator.load("qt_" + locale,
-    #                      QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
-    #    application.installTranslator(qt_translator)
-    #elif qt_translator.load("qt_" + sys_locale,
-    #                        QLibraryInfo.location(QLibraryInfo.TranslationsPath)):
-    #    print "Qt base translator with default locale loaded!"
-    #    application.installTranslator(qt_translator)
-        # Try to load Qt base translator according to system locale.
-    #else:
-    #    print "Unable to load Qt base translator!"
+    if locale is None: locale="fr"
     
-    global eficas_translator
     if locale=="ang" : locale="en"
-    #print "eficas_" + locale, monPath
-    if eficas_translator.load("eficas_" + locale, monPath):
-        QApplication.installTranslator(eficas_translator)
-        print "chargement eficas_", locale, monPath
-    else:
-        print "Unable to load Eficas translator!"
 
-    
+    if file != None and debug :
+       print ('chargement de ', file,monPath)
+       print (eficas_translator.load(file,monPath))
+       print (QApplication.installTranslator(eficas_translator))
+    elif eficas_translator.load("eficas_" + locale, monPath):
+       QApplication.installTranslator(eficas_translator)
+    elif debug:
+       print ("Unable to load Eficas translator!")
+     
+    global code_translator
+    if translatorFichier != None :
+       if (code_translator.load(translatorFichier)) and debug:
+           print (translatorFichier, ' loaded')
+       elif (code_translator.load(translatorFichier+'_'+locale) and debug):
+           print(translatorFichier+'_'+locale+ ' loaded')
+       elif debug : 
+           print ("Unable to load Code translator! No file or No translation" + translatorFichier)
+       if debug : print (QApplication.installTranslator(code_translator))
+       
 
 if __name__ == "__main__":
     import sys