Skip to content

Commit

Permalink
fix: wrap locale reading in try/except statement
Browse files Browse the repository at this point in the history
  • Loading branch information
merydian committed Jul 29, 2024
1 parent 2b981c1 commit ec3446a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions ORStools/ORStoolsPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from qgis.gui import QgisInterface
from qgis.core import QgsApplication, QgsSettings
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication
from qgis.PyQt.QtCore import QTranslator, qVersion, QCoreApplication, QLocale
import os.path

from .gui import ORStoolsDialog
Expand All @@ -56,15 +56,22 @@ def __init__(self, iface: QgisInterface) -> None:
self.plugin_dir = os.path.dirname(__file__)

# initialize locale
locale = QgsSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
try:
locale = QgsSettings().value("locale/userLocale")
if not locale:
locale = QLocale().name()
locale = locale[0:2]

locale_path = os.path.join(self.plugin_dir, "i18n", "orstools_{}.qm".format(locale))

if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)

if qVersion() > "4.3.3":
QCoreApplication.installTranslator(self.translator)
except TypeError:
pass

def initGui(self) -> None:
"""Create the menu entries and toolbar icons inside the QGIS GUI."""
Expand Down

0 comments on commit ec3446a

Please sign in to comment.