]> SALOME platform Git repositories - tools/eficas.git/blob - Extensions/localisation.py
Salome HOME
reindent + copyright + merge manuel avec la V9_dev sauf repertoires metier
[tools/eficas.git] / Extensions / localisation.py
1 # -*- coding: utf-8 -*-
2 # copyright 2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
3 # contact http://www.logilab.fr -- mailto:contact@logilab.fr
4 #
5 # This program is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation, either version 2.1 of the License, or (at your option)
8 # any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License along
16 # with this program. If not, see <http://www.gnu.org/licenses/>.
17 """
18
19 """
20
21 from __future__ import absolute_import
22 from __future__ import print_function
23 import os
24
25 try :
26     from PyQt5.QtCore import QTranslator
27     code_translator = QTranslator()
28     eficas_translator = QTranslator()
29 except :
30     code_translator = None
31     eficas_translator = None
32     print ('pas d import de qt, pas de traduction')
33
34
35
36 def localise(application, locale=None,file=None,translatorFichier=None, debug=False ):
37     """
38     """
39     if code_translator == None :
40         print ('qt not avalaible, no translation')
41         return
42     from PyQt5.QtCore import QLibraryInfo
43     from PyQt5.QtCore import QLocale
44     from PyQt5.QtWidgets import QApplication
45     monPath=os.path.join(os.path.dirname(__file__),'..','UiQT5')
46
47     sys_locale = QLocale.system().name()
48
49     if locale is None: locale="fr"
50     if locale=="ang" : locale="en"
51
52     if file != None and debug :
53         print ('chargement de ', file,monPath)
54         print (eficas_translator.load(file,monPath))
55         print (QApplication.installTranslator(eficas_translator))
56     elif eficas_translator.load("eficas_" + locale, monPath):
57         QApplication.installTranslator(eficas_translator)
58     elif debug:
59         print ("Unable to load Eficas translator!")
60
61     if debug : print  ('translatorFichier :' ,translatorFichier)
62     if translatorFichier != None :
63         if (code_translator.load(translatorFichier)) and debug:
64             print (translatorFichier, ' loaded')
65         elif (code_translator.load(translatorFichier+'_'+locale) and debug):
66             print(translatorFichier+'_'+locale+ ' loaded')
67         elif debug :
68             print ("Unable to load Code translator! No file or No translation" + translatorFichier)
69         if debug : print (QApplication.installTranslator(code_translator))
70         else : QApplication.installTranslator(code_translator)
71
72
73 if __name__ == "__main__":
74     import sys
75     localise(sys.argv[1])