-
Notifications
You must be signed in to change notification settings - Fork 7
/
__init__.py
79 lines (62 loc) · 2.29 KB
/
__init__.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
"""
This tool helps create, update, upload and download Cadasta projects.
- **Module cadasta.**
This script initializes the plugin, making it known to QGIS.
Contact : [email protected]
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import sys
import os
__copyright__ = "Copyright 2016, Cadasta Project"
__license__ = "GPL version 3"
__email__ = "[email protected]"
__revision__ = '$Format:%H$'
sys.path.append(os.path.dirname(__file__))
from PyQt4.QtCore import (
QLocale,
QTranslator,
QCoreApplication,
QSettings)
# Setup internationalisation for the plugin.
#
# See if QGIS wants to override the system locale
# and then see if we can get a valid translation file
# for whatever locale is effectively being used.
override_flag = QSettings().value(
'locale/overrideFlag', True, type=bool)
if override_flag:
locale_name = QSettings().value('locale/userLocale', 'en_US', type=str)
else:
locale_name = QLocale.system().name()
# NOTES: we split the locale name because we need the first two
# character i.e. 'id', 'af, etc
locale_name = str(locale_name).split('_')[0]
# Also set the system locale to the user overridden local
# so that the cadasta library functions gettext will work
# .. see:: :py:func:`common.utilities`
os.environ['LANG'] = str(locale_name)
root = os.path.abspath(os.path.join(os.path.dirname(__file__)))
translation_path = os.path.join(
root, 'i18n',
str(locale_name) + '.qm')
if os.path.exists(translation_path):
translator = QTranslator()
result = translator.load(translation_path)
if not result:
message = 'Failed to load translation for %s' % locale_name
raise Exception(message)
# noinspection PyTypeChecker,PyCallByClass
QCoreApplication.installTranslator(translator)
# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load Cadasta class from file Cadasta.
:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""
#
from cadasta.plugin import CadastaPlugin
return CadastaPlugin(iface)