A spot of refactoring

This commit is contained in:
Kovid Goyal 2018-03-14 09:18:52 +05:30
parent a0e87cb532
commit c088f7e818
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 14 deletions

View File

@ -9,20 +9,9 @@ __docformat__ = 'restructuredtext en'
from calibre.gui2 import gui_prefs
from calibre.gui2.complete2 import EditWithComplete
from calibre.utils.localization import lang_map
from calibre.utils.localization import lang_map_for_ui
from calibre.utils.icu import sort_key, lower
_lang_map = None
def get_lang_map():
global _lang_map
if _lang_map is None:
_lang_map = lang_map().copy()
for x in ('zxx', 'mis', 'mul'):
_lang_map.pop(x, None)
return _lang_map
class LanguagesEdit(EditWithComplete):
@ -33,7 +22,7 @@ class LanguagesEdit(EditWithComplete):
self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon)
self.setMinimumContentsLength(20)
self._lang_map = get_lang_map()
self._lang_map = lang_map_for_ui()
self.names_with_commas = [x for x in self._lang_map.itervalues() if ',' in x]
self.comma_map = {k:k.replace(',', '|') for k in self.names_with_commas}
self.comma_rmap = {v:k for k, v in self.comma_map.iteritems()}
@ -114,4 +103,3 @@ class LanguagesEdit(EditWithComplete):
if code is None:
bad.append(name)
return bad

View File

@ -426,6 +426,16 @@ def lang_map():
return _lang_map
def lang_map_for_ui():
ans = getattr(lang_map_for_ui, 'ans', None)
if ans is None:
ans = lang_map().copy()
for x in ('zxx', 'mis', 'mul'):
ans.pop(x, None)
lang_map_for_ui.ans = ans
return ans
def langnames_to_langcodes(names):
'''
Given a list of localized language names return a mapping of the names to 3