mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Supports i18n console output
This commit is contained in:
parent
1c4a38c700
commit
ed403ad8ff
1
CHANGES
1
CHANGES
@ -40,6 +40,7 @@ Features added
|
||||
* :confval:`source_suffix` allows a mapping fileext to file types
|
||||
* Add :confval:`author` as a configuration value
|
||||
* #2852: imgconverter: Support to convert GIF to PNG
|
||||
* ``sphinx-build`` command supports i18n console output
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@ -1124,6 +1124,7 @@ class Sphinx(object):
|
||||
.. versionadded:: 1.8
|
||||
"""
|
||||
locale.init([locale_dir], self.config.language, catalog)
|
||||
locale.init_console(locale_dir, catalog)
|
||||
|
||||
# ---- other methods -------------------------------------------------
|
||||
def is_parallel_allowed(self, typ):
|
||||
|
@ -11,6 +11,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import locale
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
@ -20,7 +21,8 @@ from typing import TYPE_CHECKING
|
||||
from docutils.utils import SystemMessage
|
||||
from six import text_type, binary_type
|
||||
|
||||
from sphinx import __display_version__
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__, package_dir
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.errors import SphinxError
|
||||
from sphinx.util import Tee, format_exception_cut_frames, save_traceback
|
||||
@ -304,6 +306,9 @@ def build_main(argv=sys.argv[1:]): # type: ignore
|
||||
|
||||
def main(argv=sys.argv[1:]): # type: ignore
|
||||
# type: (List[unicode]) -> int
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
||||
|
||||
if sys.argv[1:2] == ['-M']:
|
||||
return make_main(argv)
|
||||
else:
|
||||
|
@ -12,6 +12,7 @@ from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import locale
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
@ -36,6 +37,7 @@ from six import PY2, PY3, text_type, binary_type
|
||||
from six.moves import input
|
||||
from six.moves.urllib.parse import quote as urlquote
|
||||
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__, package_dir
|
||||
from sphinx.util import texescape
|
||||
from sphinx.util.console import ( # type: ignore
|
||||
@ -598,6 +600,9 @@ Makefile to be used with sphinx-build.
|
||||
|
||||
def main(argv=sys.argv[1:]):
|
||||
# type: (List[str]) -> int
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
||||
|
||||
if not color_terminal():
|
||||
nocolor()
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
@ -19,6 +19,7 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import glob
|
||||
import locale
|
||||
import os
|
||||
import sys
|
||||
from fnmatch import fnmatch
|
||||
@ -27,7 +28,8 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from six import binary_type
|
||||
|
||||
from sphinx import __display_version__
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__, package_dir
|
||||
from sphinx.cmd.quickstart import EXTENSIONS
|
||||
from sphinx.util import rst
|
||||
from sphinx.util.osutil import FileAvoidWrite, ensuredir, walk
|
||||
@ -382,6 +384,9 @@ Note: By default this script will not overwrite already created files.""")
|
||||
def main(argv=sys.argv[1:]):
|
||||
# type: (List[str]) -> int
|
||||
"""Parse and check the command line arguments."""
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
||||
|
||||
parser = get_parser()
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
|
@ -21,6 +21,7 @@ from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import codecs
|
||||
import locale
|
||||
import os
|
||||
import pydoc
|
||||
import re
|
||||
@ -30,6 +31,7 @@ from typing import TYPE_CHECKING
|
||||
from jinja2 import FileSystemLoader, TemplateNotFound
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
|
||||
import sphinx.locale
|
||||
from sphinx import __display_version__
|
||||
from sphinx import package_dir
|
||||
from sphinx.ext.autosummary import import_by_name, get_documenter
|
||||
@ -402,6 +404,9 @@ The format of the autosummary directive is documented in the
|
||||
|
||||
def main(argv=sys.argv[1:]):
|
||||
# type: (List[str]) -> None
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
sphinx.locale.init_console(os.path.join(package_dir, 'locale'), 'sphinx')
|
||||
|
||||
app = DummyApplication()
|
||||
setup_documenters(app)
|
||||
args = get_parser().parse_args(argv)
|
||||
|
@ -10,6 +10,7 @@
|
||||
"""
|
||||
|
||||
import gettext
|
||||
import locale
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from gettext import NullTranslations
|
||||
@ -203,16 +204,6 @@ def lazy_gettext(string):
|
||||
translators = defaultdict(NullTranslations) # type: Dict[Tuple[unicode, unicode], NullTranslations] # NOQA
|
||||
|
||||
|
||||
def __(message, *args):
|
||||
# type: (unicode, *Any) -> unicode
|
||||
"""A dummy wrapper to i18n'ize exceptions and command line messages.
|
||||
|
||||
In future, the messages are translated using LC_MESSAGES or any other
|
||||
locale settings.
|
||||
"""
|
||||
return message if len(args) <= 1 else args[0]
|
||||
|
||||
|
||||
def init(locale_dirs, language, catalog='sphinx', namespace='general'):
|
||||
# type: (List, unicode, unicode) -> Tuple[Any, bool]
|
||||
"""Look for message catalogs in `locale_dirs` and *ensure* that there is at
|
||||
@ -256,6 +247,13 @@ def init(locale_dirs, language, catalog='sphinx', namespace='general'):
|
||||
return translator, has_translation
|
||||
|
||||
|
||||
def init_console(locale_dir, catalog):
|
||||
# type: (unicode, unicode) -> None
|
||||
"""Initialize locale for console."""
|
||||
language, _ = locale.getlocale(locale.LC_MESSAGES) # encoding is ignored
|
||||
return init([locale_dir], language, catalog, 'console')
|
||||
|
||||
|
||||
def get_translator(catalog='sphinx', namespace='general'):
|
||||
# type: (unicode, unicode) -> NullTranslations
|
||||
return translators[(namespace, catalog)]
|
||||
@ -313,6 +311,7 @@ def get_translation(catalog, namespace='general'):
|
||||
|
||||
# A shortcut for sphinx-core
|
||||
_ = get_translation('sphinx')
|
||||
__ = get_translation('sphinx', 'console')
|
||||
|
||||
|
||||
def l_(*args):
|
||||
|
Loading…
Reference in New Issue
Block a user