Try to use the right country variant english dictionary by default, based on the users locale settings

This commit is contained in:
Kovid Goyal 2014-04-12 23:21:43 +05:30
parent 7d442f9320
commit b4bd343ed7
2 changed files with 7 additions and 3 deletions

View File

@ -285,7 +285,7 @@ def get_windows_temp_path():
def get_windows_user_locale_name(): def get_windows_user_locale_name():
import ctypes import ctypes
k32 = ctypes.windll.kernel32 k32 = ctypes.windll.kernel32
n = 200 n = 255
buf = ctypes.create_unicode_buffer(u'\0'*n) buf = ctypes.create_unicode_buffer(u'\0'*n)
n = k32.GetUserDefaultLocaleName(buf, n) n = k32.GetUserDefaultLocaleName(buf, n)
if n == 0: if n == 0:

View File

@ -12,7 +12,7 @@ from operator import attrgetter
from calibre.constants import plugins, config_dir from calibre.constants import plugins, config_dir
from calibre.utils.config import JSONConfig from calibre.utils.config import JSONConfig
from calibre.utils.localization import get_lang, canonicalize_lang from calibre.utils.localization import get_lang, canonicalize_lang, get_system_locale
DictionaryLocale = namedtuple('DictionaryLocale', 'langcode countrycode') DictionaryLocale = namedtuple('DictionaryLocale', 'langcode countrycode')
Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id') Dictionary = namedtuple('Dictionary', 'primary_locale locales dicpath affpath builtin name id')
@ -82,7 +82,11 @@ def custom_dictionaries(reread=False):
_custom = frozenset(dics) _custom = frozenset(dics)
return _custom return _custom
default_preferred_locales = {'eng':'en-US', 'deu':'de-DE', 'spa':'es-ES', 'fra':'fr-FR'} default_en_locale = 'en-US'
ul = parse_lang_code(get_system_locale())
if ul is not None and ul.langcode == 'eng' and ul.countrycode in 'GB BS BZ GH IE IN JM NZ TT'.split():
default_en_locale = 'en-' + ul.countrycode
default_preferred_locales = {'eng':default_en_locale, 'deu':'de-DE', 'spa':'es-ES', 'fra':'fr-FR'}
def best_locale_for_language(langcode): def best_locale_for_language(langcode):
best_locale = dprefs['preferred_locales'].get(langcode, default_preferred_locales.get(langcode, None)) best_locale = dprefs['preferred_locales'].get(langcode, default_preferred_locales.get(langcode, None))