فهرست منبع

Fix loading of language override setting. Fixes #1489 (#1990)

The problem was caused by a new settings file.
Māris Nartišs 3 سال پیش
والد
کامیت
8ae6631eaf
1فایلهای تغییر یافته به همراه12 افزوده شده و 14 حذف شده
  1. 12 14
      lib/init/grass.py

+ 12 - 14
lib/init/grass.py

@@ -55,6 +55,7 @@ import locale
 import uuid
 import uuid
 import unicodedata
 import unicodedata
 import argparse
 import argparse
+import json
 
 
 
 
 # mechanism meant for debugging this script (only)
 # mechanism meant for debugging this script (only)
@@ -1369,29 +1370,26 @@ def set_language(grass_config_dir):
     # See discussion for Windows not following its own documentation and
     # See discussion for Windows not following its own documentation and
     # not accepting ISO codes as valid locale identifiers
     # not accepting ISO codes as valid locale identifiers
     # http://bugs.python.org/issue10466
     # http://bugs.python.org/issue10466
-    language = "None"  # Such string sometimes is present in wx file
+    # As this code relies heavily on various locale calls, it is necessary
+    # to track related python changes:
+    # https://bugs.python.org/issue43557
     encoding = None
     encoding = None
 
 
     # Override value is stored in wxGUI preferences file.
     # Override value is stored in wxGUI preferences file.
-    # As it's the only thing required, we'll just grep it out.
     try:
     try:
-        fd = open(os.path.join(grass_config_dir, "wx"), "r")
-    except:
-        # Even if there is no override, we still need to set locale.
-        pass
-    else:
-        for line in fd:
-            if re.search("^language", line):
-                line = line.rstrip(" %s" % os.linesep)
-                language = "".join(line.split(";")[-1:])
-                break
-        fd.close()
+        with open(os.path.join(grass_config_dir, "wx.json"), "r") as json_file:
+            try:
+                language = json.load(json_file)["language"]["locale"]["lc_all"]
+            except KeyError:
+                language = None
+    except FileNotFoundError:
+        language = None
 
 
     # Backwards compatibility with old wx preferences files
     # Backwards compatibility with old wx preferences files
     if language == "C":
     if language == "C":
         language = "en"
         language = "en"
 
 
-    if language == "None" or language == "" or not language:
+    if not language:
         # Language override is disabled (system language specified)
         # Language override is disabled (system language specified)
         # As by default program runs with C locale, but users expect to
         # As by default program runs with C locale, but users expect to
         # have their default locale, we'll just set default locale
         # have their default locale, we'll just set default locale