Georg Brandl avatar Georg Brandl committed 2c2e7bb

Make the _ gettext alias an explicit import instead of installing into builtins.

Comments (0)

Files changed (23)

sphinx/builders/changes.py

 
 from sphinx import package_dir
 from sphinx.util import copy_static_entry
+from sphinx.locale import _
 from sphinx.theming import Theme
 from sphinx.builders import Builder
 from sphinx.util.osutil import ensuredir, os_path

sphinx/builders/devhelp.py

     :license: BSD, see LICENSE for details.
 """
 
-import os
 import re
-import cgi
-import sys
 from os import path
 
 from docutils import nodes

sphinx/builders/html.py

 from sphinx.util.matching import patmatch, compile_matchers
 from sphinx.util.pycompat import any
 from sphinx.errors import SphinxError
+from sphinx.locale import _
 from sphinx.search import js_index
 from sphinx.theming import Theme
 from sphinx.builders import Builder

sphinx/builders/htmlhelp.py

 from docutils import nodes
 
 from sphinx import addnodes
+from sphinx.locale import _
 from sphinx.builders.html import StandaloneHTMLBuilder
 
 

sphinx/builders/latex.py

 
 from sphinx import package_dir, addnodes
 from sphinx.util import texescape
+from sphinx.locale import _
 from sphinx.builders import Builder
 from sphinx.environment import NoUri
 from sphinx.util.nodes import inline_all_toctrees

sphinx/builders/qthelp.py

 from docutils import nodes
 
 from sphinx import addnodes
+from sphinx.locale import _
 from sphinx.builders.html import StandaloneHTMLBuilder
 
 _idpattern = re.compile(
                 shortname = shortname[:-2]
             id = '%s.%s' % (id, shortname)
         else:
-            id = descr = None
+            id = None
 
         if id:
             item = ' '*12 + '<keyword name="%s" id="%s" ref="%s"/>' % (

sphinx/directives/other.py

 from docutils.parsers.rst import Directive, directives
 
 from sphinx import addnodes
-from sphinx.locale import pairindextypes
+from sphinx.locale import pairindextypes, _
 from sphinx.util import url_re, docname_join
 from sphinx.util.nodes import explicit_title_re
 from sphinx.util.compat import make_admonition

sphinx/domains/c.py

 
 from sphinx import addnodes
 from sphinx.roles import XRefRole
-from sphinx.locale import l_
+from sphinx.locale import l_, _
 from sphinx.domains import Domain, ObjType
 from sphinx.directives import ObjectDescription
 from sphinx.util.nodes import make_refnode

sphinx/domains/python.py

 
 from sphinx import addnodes
 from sphinx.roles import XRefRole
-from sphinx.locale import l_
+from sphinx.locale import l_, _
 from sphinx.domains import Domain, ObjType
 from sphinx.directives import ObjectDescription
 from sphinx.util.nodes import make_refnode

sphinx/domains/std.py

 
 from sphinx import addnodes
 from sphinx.roles import XRefRole
-from sphinx.locale import l_
+from sphinx.locale import l_, _
 from sphinx.domains import Domain, ObjType
 from sphinx.directives import ObjectDescription
 from sphinx.util import ws_re

sphinx/environment.py

 from sphinx.util.osutil import movefile, SEP, ustrftime
 from sphinx.util.matching import compile_matchers
 from sphinx.errors import SphinxError, ExtensionError
+from sphinx.locale import _
 
 
 orig_role_function = roles.role

sphinx/ext/autodoc.py

 from docutils.statemachine import ViewList
 
 from sphinx.util import rpartition, force_decode
+from sphinx.locale import _
 from sphinx.pycode import ModuleAnalyzer, PycodeError
 from sphinx.application import ExtensionError
 from sphinx.util.nodes import nested_parse_with_titles
         return ret
 
     def format_args(self):
-        args = None
         # for classes, the relevant signature is the __init__ method's
         initmeth = self.get_attr(self.object, '__init__', None)
         # classes without __init__ method, default __init__ or

sphinx/ext/autosummary/__init__.py

 from docutils.statemachine import ViewList
 from docutils import nodes
 
-from sphinx import addnodes, roles
+from sphinx import addnodes
 from sphinx.util.compat import Directive
 
 
 
         if 'toctree' in self.options:
             suffix = env.config.source_suffix
-            all_docnames = env.found_docs.copy()
             dirname = posixpath.dirname(env.docname)
 
             tree_prefix = self.options['toctree'].strip()

sphinx/ext/inheritance_diagram.py

 
         # two possibilities: either it is a module, then import it
         try:
-            module = __import__(fullname)
+            __import__(fullname)
             todoc = sys.modules[fullname]
         except ImportError:
             # else it is a class, then import the module
                         'Could not import class %r specified for '
                         'inheritance diagram' % base)
             try:
-                module = __import__(path)
+                __import__(path)
                 todoc = getattr(sys.modules[path], base)
             except (ImportError, AttributeError):
                 raise InheritanceException(

sphinx/ext/todo.py

 
 from docutils import nodes
 
+from sphinx.locale import _
 from sphinx.environment import NoUri
 from sphinx.util.compat import Directive, make_admonition
 

sphinx/ext/viewcode.py

 from docutils import nodes
 
 from sphinx import addnodes
+from sphinx.locale import _
 from sphinx.pycode import ModuleAnalyzer
 from sphinx.util.nodes import make_refnode
 

sphinx/locale/__init__.py

 import gettext
 import UserString
 
-from sphinx import package_dir
-
 
 class _TranslationProxy(UserString.UserString, object):
     """Class for proxy strings from gettext translations.  This is a helper
     'builtin':   l_('built-in function'),
 }
 
+translator = None
+
+def _(message):
+    return translator.gettext(message)
 
 def init(locale_dirs, language):
+    global translator
     # the None entry is the system's default locale path
-    translator = None
     has_translation = True
     for dir_ in locale_dirs:
         try:
     if translator is None:
         translator = gettext.NullTranslations()
         has_translation = False
-    translator.install(unicode=True)
     return translator, has_translation

sphinx/pycode/pgen2/grammar.py

 import pickle
 
 # Local imports
-from sphinx.pycode.pgen2 import token, tokenize
+from sphinx.pycode.pgen2 import token
 
 
 class Grammar(object):

sphinx/pycode/pgen2/pgen.py

             #self.dump_nfa(name, a, z)
             dfa = self.make_dfa(a, z)
             #self.dump_dfa(name, dfa)
-            oldlen = len(dfa)
+            #oldlen = len(dfa)
             self.simplify_dfa(dfa)
-            newlen = len(dfa)
+            #newlen = len(dfa)
             dfas[name] = dfa
             #print name, oldlen, newlen
             if startsymbol is None:
 from docutils.parsers.rst import roles
 
 from sphinx import addnodes
+from sphinx.locale import _
 from sphinx.util import ws_re
 from sphinx.util.nodes import split_explicit_title
 
         # if the first character is a bang, don't cross-reference at all
         if text[0:1] == '!':
             if self.fix_parens:
-                text, _ = self._fix_parens(env, False, text[1:], "")
+                text, tgt = self._fix_parens(env, False, text[1:], "")
             innernode = self.innernodeclass(rawtext, text, classes=['xref'])
             return self.result_nodes(inliner.document, env, innernode,
                                      is_ref=False)

sphinx/writers/html.py

 from docutils import nodes
 from docutils.writers.html4css1 import Writer, HTMLTranslator as BaseTranslator
 
-from sphinx.locale import admonitionlabels, versionlabels
+from sphinx.locale import admonitionlabels, versionlabels, _
 from sphinx.util.smartypants import sphinx_smarty_pants
 
 try:

sphinx/writers/latex.py

 from sphinx import addnodes
 from sphinx import highlighting
 from sphinx.errors import SphinxError
-from sphinx.locale import admonitionlabels, versionlabels
+from sphinx.locale import admonitionlabels, versionlabels, _
 from sphinx.util.osutil import ustrftime
 from sphinx.util.texescape import tex_escape_map
 from sphinx.util.smartypants import educateQuotesLatex

sphinx/writers/text.py

 from docutils import nodes, writers
 
 from sphinx import addnodes
-from sphinx.locale import admonitionlabels, versionlabels
+from sphinx.locale import admonitionlabels, versionlabels, _
 
 
 class TextWriter(writers.Writer):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.