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
|
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>
---
pyanaconda/localization.py | 18 +++++++++++++++++-
pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py | 2 ++
pyanaconda/ui/tui/spokes/language_support.py | 5 +++--
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/localization.py b/pyanaconda/localization.py
index 20908ef..18d4be9 100644
--- a/pyanaconda/localization.py
+++ b/pyanaconda/localization.py
@@ -27,7 +27,7 @@ import glob
from collections import namedtuple
from pyanaconda.core import constants, util
-from pyanaconda.core.util import upcase_first_letter, setenv, execWithRedirect
+from pyanaconda.core.util import upcase_first_letter, setenv, execWithRedirect, execReadlines
from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)
@@ -776,3 +776,19 @@ def strip_codeset_and_modifier(locale):
if '.' in locale:
locale = locale[:locale.find('.')]
return locale
+
+_all_locales = []
+def list_all_locales():
+ global _all_locales
+
+ if _all_locales == []:
+ for lang in execReadlines("locale", ["-a"]):
+ parts= parse_langcode(lang)
+ locales = langtable.list_locales(languageId=parts["language"],
+ territoryId=parts.get("territory", ""),
+ scriptId=parts.get("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 6380c14..c4e361b 100644
--- a/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
+++ b/pyanaconda/ui/gui/spokes/lib/lang_locale_handler.py
@@ -166,6 +166,8 @@ class LangLocaleHandler(object):
locales = localization.get_language_locales(lang)
locales = self._filter_locales(lang, locales)
for locale in locales:
+ 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 f4e8f48..9a48a78 100644
--- a/pyanaconda/ui/tui/spokes/language_support.py
+++ b/pyanaconda/ui/tui/spokes/language_support.py
@@ -97,8 +97,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
|