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
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)
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
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/>.
21 from __future__ import absolute_import
22 from __future__ import print_function
25 from PyQt5.QtCore import QTranslator
27 code_translator = QTranslator()
28 eficas_translator = QTranslator()
30 def localise(application, locale=None,file=None,translatorFichier=None, debug=False ):
33 from PyQt5.QtCore import QLibraryInfo
34 from PyQt5.QtCore import QLocale
35 from PyQt5.QtWidgets import QApplication
36 monPath=os.path.join(os.path.dirname(__file__),'..','UiQT5')
38 sys_locale = QLocale.system().name()
40 if locale is None: locale="fr"
42 if locale=="ang" : locale="en"
44 if file != None and debug :
45 print ('chargement de ', file,monPath)
46 print (eficas_translator.load(file,monPath))
47 print (QApplication.installTranslator(eficas_translator))
48 elif eficas_translator.load("eficas_" + locale, monPath):
49 QApplication.installTranslator(eficas_translator)
51 print ("Unable to load Eficas translator!")
53 global code_translator
54 if translatorFichier != None :
55 if (code_translator.load(translatorFichier)):
56 print (translatorFichier, ' loaded')
57 elif (code_translator.load(translatorFichier+'_'+locale)):
58 print(translatorFichier+'_'+locale+ ' loaded')
60 print ("Unable to load Code translator! No file or No translation" + translatorFichier)
61 if debug : print (QApplication.installTranslator(code_translator))
64 if __name__ == "__main__":