Skip to content

Commit 9f27d74

Browse files
committed
refactor: parameterize the root prefix number of characters
To make i18n work on windows, we need to clean the three character root elements(drive letter, colon, backslash) from the front of the various paths. Parameterize the number of chars. Old way hard coded to 1, which leaves :/ in the path and generates bad LOCALE_DIRS. From issues getting Roundup running on windows discussed on mailing list by Simon Eigeldinger. Thread starts with: https://sourceforge.net/p/roundup/mailman/message/41557096/ subject: Installing Roundup on Windows 2023-10-05.
1 parent dd9507a commit 9f27d74

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

roundup/i18n.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@
5252
# locale root is prefix/share/locale.
5353
if os.name == "nt":
5454
_mo_path = [".."] * 4 + ["share", "locale"]
55+
root_prefix_chars = 3 # remove c:\ or other drive letter
5556
else:
5657
_mo_path = [".."] * 5 + ["share", "locale"]
58+
root_prefix_chars = 1 # remove /
59+
5760
_mo_path = os.path.normpath(os.path.join(msgfmt.__file__, *_mo_path))
5861
if _mo_path not in LOCALE_DIRS:
5962
LOCALE_DIRS.append(_mo_path)
@@ -67,18 +70,18 @@
6770
for _N in 1, 2:
6871
path = os.path.dirname(path)
6972
# path is /usr/local/lib/python3.10/site-packages
70-
_ldir = os.path.join(path, sys.prefix[1:], 'share', 'locale')
73+
_ldir = os.path.join(path, sys.prefix[root_prefix_chars:], 'share', 'locale')
7174
if os.path.isdir(_ldir):
7275
LOCALE_DIRS.append(_ldir)
7376
# try other places locale files are hidden on install
74-
_ldir = os.path.join(path, sys.prefix[1:], 'local', 'share', 'locale')
77+
_ldir = os.path.join(path, sys.prefix[root_prefix_chars:], 'local', 'share', 'locale')
7578
if os.path.isdir(_ldir):
7679
LOCALE_DIRS.append(_ldir)
7780
try:
78-
_ldir = os.path.join(path, sys.base_prefix[1:], 'local', 'share', 'locale')
81+
_ldir = os.path.join(path, sys.base_prefix[root_prefix_chars:], 'local', 'share', 'locale')
7982
if os.path.isdir(_ldir):
8083
LOCALE_DIRS.append(_ldir)
81-
_ldir = os.path.join(path, sys.base_prefix[1:], 'share', 'locale')
84+
_ldir = os.path.join(path, sys.base_prefix[root_prefix_chars:], 'share', 'locale')
8285
if os.path.isdir(_ldir):
8386
LOCALE_DIRS.append(_ldir)
8487
except AttributeError:

0 commit comments

Comments
 (0)