/
translate.py
44 lines (37 loc) · 1.56 KB
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Name : Translate
Description : Class for translate Plugin
Date : 2018-10-19
copyright : (C) 2018 by Luiz Motta
email : motta.luiz@gmail.com
***************************************************************************/
For create file 'qm'
1) Install pyqt5-dev-tools
2) Define that files need for translation: pluginname.pro
3) Create 'ts': pylupdate5 -verbose pluginname.pro
4) Edit your translation: QtLinquist (use Release for create 'qm' file)
"""
__author__ = 'Luiz Motta'
__date__ = '2018-10-19'
__copyright__ = '(C) 2018, Luiz Motta'
__revision__ = '$Format:%H$'
import os
from qgis.PyQt.QtCore import QFileInfo, QSettings, QLocale, QTranslator, QCoreApplication
from qgis.core import QgsApplication
class Translate():
def __init__(self, pluginName):
def getFile():
overrideLocale = QSettings().value('locale/overrideFlag', False, type=bool)
localeFullName = QLocale.system().name() if not overrideLocale else QSettings().value('locale/userLocale', '')
qmPathFile = f"i18n/{pluginName}_{localeFullName}.qm"
pluginPath = os.path.dirname(__file__)
translationFile = f"{pluginPath}/{qmPathFile}"
return translationFile
self.translator = None
translationFile = getFile()
if QFileInfo( translationFile ).exists():
self.translator = QTranslator()
self.translator.load( translationFile )
QCoreApplication.installTranslator( self.translator )