mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A spot of refactoring
This commit is contained in:
parent
a0e87cb532
commit
c088f7e818
@ -9,20 +9,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
from calibre.gui2 import gui_prefs
|
from calibre.gui2 import gui_prefs
|
||||||
from calibre.gui2.complete2 import EditWithComplete
|
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
|
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):
|
class LanguagesEdit(EditWithComplete):
|
||||||
|
|
||||||
@ -33,7 +22,7 @@ class LanguagesEdit(EditWithComplete):
|
|||||||
|
|
||||||
self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon)
|
self.setSizeAdjustPolicy(self.AdjustToMinimumContentsLengthWithIcon)
|
||||||
self.setMinimumContentsLength(20)
|
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.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_map = {k:k.replace(',', '|') for k in self.names_with_commas}
|
||||||
self.comma_rmap = {v:k for k, v in self.comma_map.iteritems()}
|
self.comma_rmap = {v:k for k, v in self.comma_map.iteritems()}
|
||||||
@ -114,4 +103,3 @@ class LanguagesEdit(EditWithComplete):
|
|||||||
if code is None:
|
if code is None:
|
||||||
bad.append(name)
|
bad.append(name)
|
||||||
return bad
|
return bad
|
||||||
|
|
||||||
|
@ -426,6 +426,16 @@ def lang_map():
|
|||||||
return _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):
|
def langnames_to_langcodes(names):
|
||||||
'''
|
'''
|
||||||
Given a list of localized language names return a mapping of the names to 3
|
Given a list of localized language names return a mapping of the names to 3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user