mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #10214: html: invalid language tag was generated for zh_CN
So far, HTML builder output the `language` configuration as a language tag for HTML. But it takes locale string in ANSI C, not IETF language code. This converts locale string to language tag to generate valid language tag for HTML.
This commit is contained in:
parent
31eba1a76d
commit
11a1dbed91
2
CHANGES
2
CHANGES
@ -67,6 +67,8 @@ Bugs fixed
|
|||||||
|
|
||||||
* #10279: autodoc: Default values for keyword only arguments in overloaded
|
* #10279: autodoc: Default values for keyword only arguments in overloaded
|
||||||
functions are rendered as a string literal
|
functions are rendered as a string literal
|
||||||
|
* #10214: html: invalid language tag was generated if :confval:`language`
|
||||||
|
contains a country code (ex. zh_CN)
|
||||||
* #10236: html search: objects are duplicated in search result
|
* #10236: html search: objects are duplicated in search result
|
||||||
* #9962: texinfo: Deprecation message for ``@definfoenclose`` command on
|
* #9962: texinfo: Deprecation message for ``@definfoenclose`` command on
|
||||||
bulding texinfo document
|
bulding texinfo document
|
||||||
|
@ -7,7 +7,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import path
|
from os import path
|
||||||
from typing import IO, Any, Dict, Iterable, Iterator, List, Set, Tuple, Type
|
from typing import IO, Any, Dict, Iterable, Iterator, List, Optional, Set, Tuple, Type
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
@ -68,6 +68,17 @@ def get_stable_hash(obj: Any) -> str:
|
|||||||
return md5(str(obj).encode()).hexdigest()
|
return md5(str(obj).encode()).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
def convert_locale_to_language_tag(locale: Optional[str]) -> Optional[str]:
|
||||||
|
"""Convert a locale string to a language tag (ex. en_US -> en-US).
|
||||||
|
|
||||||
|
refs: BCP 47 (:rfc:`5646`)
|
||||||
|
"""
|
||||||
|
if locale:
|
||||||
|
return locale.replace('_', '-')
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Stylesheet(str):
|
class Stylesheet(str):
|
||||||
"""A metadata of stylesheet.
|
"""A metadata of stylesheet.
|
||||||
|
|
||||||
@ -510,7 +521,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
'file_suffix': self.out_suffix,
|
'file_suffix': self.out_suffix,
|
||||||
'link_suffix': self.link_suffix,
|
'link_suffix': self.link_suffix,
|
||||||
'script_files': self.script_files,
|
'script_files': self.script_files,
|
||||||
'language': self.config.language,
|
'language': convert_locale_to_language_tag(self.config.language),
|
||||||
'css_files': self.css_files,
|
'css_files': self.css_files,
|
||||||
'sphinx_version': __display_version__,
|
'sphinx_version': __display_version__,
|
||||||
'sphinx_version_tuple': sphinx_version,
|
'sphinx_version_tuple': sphinx_version,
|
||||||
|
Loading…
Reference in New Issue
Block a user