Skip to content

Commit d6bb4b7

Browse files
committed
Fixed translation tools compat. with Python 3.11
1 parent c9a66fa commit d6bb4b7

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

guidata/configtools.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
The ``guidata.configtools`` module provides configuration related tools.
1313
"""
1414

15+
import gettext
1516
import os
1617
import os.path as osp
1718
import sys
18-
import gettext
1919

20-
from guidata.utils import get_module_path, decode_fs_string
20+
from guidata.utils import decode_fs_string, get_module_path
2121

2222
IMG_PATH = []
2323

@@ -50,9 +50,12 @@ def get_translation(modname, dirname=None):
5050
if lang is not None:
5151
os.environ["LANG"] = lang
5252
try:
53-
_trans = gettext.translation(
54-
modname, get_module_locale_path(dirname), codeset="utf-8"
55-
)
53+
modlocpath = get_module_locale_path(dirname)
54+
try:
55+
_trans = gettext.translation(modname, modlocpath, codeset="utf-8")
56+
except TypeError:
57+
# Python >= 3.11 (codeset argument has been removed)
58+
_trans = gettext.translation(modname, modlocpath)
5659
lgettext = _trans.gettext
5760

5861
def translate_gettext(x):
@@ -162,8 +165,8 @@ def get_image_layout(imagename, text="", tooltip="", alignment=None):
162165
left-aligned text [with specified tooltip]
163166
Return (layout, label)
164167
"""
165-
from qtpy import QtWidgets as QW
166168
from qtpy import QtCore as QC
169+
from qtpy import QtWidgets as QW
167170

168171
if alignment is None:
169172
alignment = QC.Qt.AlignLeft
@@ -261,8 +264,8 @@ def get_pen(conf, section, option="", color="black", width=1, style="SolidLine")
261264
[width]: default width
262265
[style]: default style
263266
"""
264-
from qtpy import QtGui as QG
265267
from qtpy import QtCore as QC
268+
from qtpy import QtGui as QG
266269

267270
if "pen" not in option:
268271
option += "/pen"

0 commit comments

Comments
 (0)