Salome HOME
except et print
[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 import os
22 from determine import monEnvQT5
23 if monEnvQT5 :
24    from PyQt5.QtCore import QTranslator
25 else :
26    from PyQt4.QtCore import QTranslator
27
28 qt_translator = QTranslator()
29 eficas_translator = QTranslator()
30
31 def localise(application, locale=None,file=None ):
32     """
33     """
34     if monEnvQT5 :
35        from PyQt5.QtCore import QLibraryInfo
36        from PyQt5.QtCore import QLocale
37        from PyQt5.QtWidgets import QApplication
38        monPath=os.path.join(os.path.dirname(__file__),'..','UiQT5')
39     else :
40        from PyQt4.QtCore import QLibraryInfo
41        from PyQt4.QtCore import QLocale
42        from PyQt4.QtGui import QApplication
43        monPath=os.path.join(os.path.dirname(__file__),'..','UiQT4')
44
45     sys_locale = QLocale.system().name()
46
47     if locale is None: locale="fr"
48     
49     global eficas_translator
50     if locale=="ang" : locale="en"
51
52     if file != None :
53        print 'chargement de ', file,monPath
54        print eficas_translator.load(file,monPath)
55        print QApplication.installTranslator(eficas_translator)
56        return
57      
58     if eficas_translator.load("eficas_" + locale, monPath):
59         QApplication.installTranslator(eficas_translator)
60     else:
61         print "Unable to load Eficas translator!"
62        
63
64 if __name__ == "__main__":
65     import sys
66     localise(sys.argv[1])