mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #4169: Chinese language doesn't trigger Chinese search automatically
This commit is contained in:
parent
77e673d08c
commit
4448902977
1
CHANGES
1
CHANGES
@ -31,6 +31,7 @@ Bugs fixed
|
||||
* #3692: Unable to build HTML if writing .buildinfo failed
|
||||
* #4152: HTML writer crashes if a field list is placed on top of the document
|
||||
* #4063: Sphinx crashes when labeling directive ``.. todolist::``
|
||||
* #4169: Chinese language doesn't trigger Chinese search automatically
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
@ -265,6 +265,11 @@ class IndexBuilder(object):
|
||||
# objtype index -> (domain, type, objname (localized))
|
||||
lang_class = languages.get(lang) # type: Type[SearchLanguage]
|
||||
# add language-specific SearchLanguage instance
|
||||
|
||||
# fallback; try again with language-code
|
||||
if lang_class is None and '_' in lang:
|
||||
lang_class = languages.get(lang.split('_')[0])
|
||||
|
||||
if lang_class is None:
|
||||
self.lang = SearchEnglish(options) # type: SearchLanguage
|
||||
elif isinstance(lang_class, str):
|
||||
|
@ -228,3 +228,15 @@ def test_IndexBuilder():
|
||||
}
|
||||
assert index._objtypes == {('dummy', 'objtype'): 0}
|
||||
assert index._objnames == {0: ('dummy', 'objtype', 'objtype')}
|
||||
|
||||
|
||||
def test_IndexBuilder_lookup():
|
||||
env = DummyEnvironment('1.0', {})
|
||||
|
||||
# zh
|
||||
index = IndexBuilder(env, 'zh', {}, None)
|
||||
assert index.lang.lang == 'zh'
|
||||
|
||||
# zh_CN
|
||||
index = IndexBuilder(env, 'zh_CN', {}, None)
|
||||
assert index.lang.lang == 'zh'
|
||||
|
Loading…
Reference in New Issue
Block a user