aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-installer/anaconda/files/0009-dynamic-detect-workable-locale.patch
blob: 9e97018f2cc52ae0922d1b597e46dc0cffbbe1cb (plain)
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
80
81
82
83
84
85
86
87
From bdc39fa5d40140a7e0184240e5106c46e31eabc9 Mon Sep 17 00:00:00 2001
From: Hongxu Jia <hongxu.jia@windriver.com>
Date: Tue, 25 Jun 2019 11:05:39 +0800
Subject: [PATCH] dynamic detect workable locale

Upstream-Status: Inappropriate [oe specific]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>

Refactor for anaconda 34.

Signed-off-by: Kai Kang <kai.kang@windriver.com>

Rebase for anaconda 37 on 20221020.

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 pyanaconda/localization.py                          | 19 ++++++++++++++++++-
 pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py |  2 ++
 pyanaconda/ui/tui/spokes/language_support.py        |  5 +++--
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index 2331fa5b15..7c7c085397 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -27,7 +27,7 @@ from collections import namedtuple
 import functools
 
 from pyanaconda.core import constants
-from pyanaconda.core.util import setenv, execWithRedirect
+from pyanaconda.core.util import setenv, execWithRedirect, execReadlines
 from pyanaconda.core.string import upcase_first_letter
 from pyanaconda.modules.common.constants.services import BOSS
 
@@ -667,3 +667,20 @@ def setup_locale_environment(locale=None, text_mode=False, prefer_environment=Fa
     for varname in ("LANGUAGE", "LC_ALL", "LC_MESSAGES"):
         if varname in os.environ:
             del os.environ[varname]
+
+
+_all_locales = []
+def list_all_locales():
+    global _all_locales
+
+    if _all_locales == []:
+        for lang in execReadlines("locale", ["-a"]):
+            parts = langtable.parse_locale(lang)
+            locales = langtable.list_locales(languageId=parts.language,
+                                             territoryId=parts.territory,
+                                             scriptId=parts.script)
+            _all_locales += locales
+
+        log.info("all locales: %s" % _all_locales)
+
+    return _all_locales
diff --git a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
index def8113df4..4e2ec18123 100644
--- a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
+++ b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
@@ -168,6 +168,8 @@ class LangLocaleHandler(object, metaclass=ABCMeta):
         for locale in locales:
             if self._only_existing_locales and not localization.locale_has_translation(locale):
                 continue
+            if locale not in localization.list_all_locales():
+                continue
             self._add_locale(self._localeStore,
                              localization.get_native_name(locale),
                              locale)
diff --git a/pyanaconda/ui/tui/spokes/language_support.py b/pyanaconda/ui/tui/spokes/language_support.py
index 59c3596508..a046238429 100644
--- a/pyanaconda/ui/tui/spokes/language_support.py
+++ b/pyanaconda/ui/tui/spokes/language_support.py
@@ -107,8 +107,9 @@ class LangSpoke(FirstbootSpokeMixIn, NormalTUISpoke):
         if args:
             self.window.add(TextWidget(_("Available locales")))
             for locale in args:
-                widget = TextWidget(localization.get_english_name(locale))
-                self._container.add(widget, self._set_locales_callback, locale)
+                if locale in localization.list_all_locales():
+                    widget = TextWidget(localization.get_english_name(locale))
+                    self._container.add(widget, self._set_locales_callback, locale)
         else:
             self.window.add(TextWidget(_("Available languages")))
             for lang in self._langs:
-- 
2.7.4