Patchwork D7435: i18n: get datapath directly from resourceutil

login
register
mail settings
Submitter phabricator
Date Nov. 15, 2019, 7:12 p.m.
Message ID <differential-rev-PHID-DREV-azjgadm6xdvbzmi2kq6s-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43281/
State Superseded
Headers show

Comments

phabricator - Nov. 15, 2019, 7:12 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The new resourceutil module is lower in the dependency graph, so we
  can depend directly on it and won't have to depend on the util module
  to inject the datapath.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7435

AFFECTED FILES
  doc/gendoc.py
  mercurial/i18n.py
  mercurial/util.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 16, 2019, 7:08 p.m.
This revision is now accepted and ready to land.
indygreg added inline comments.
indygreg accepted this revision.

INLINE COMMENTS

> i18n.py:57
> +    _ugettext = t.gettext
>  
>  

I'm not thrilled about the use of global variables here: I feel like the locale directory and related functionality should be associated with a `ui` instance or something. But this was an existing can of worms and you didn't make anything worse. So this is fine for now.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7435/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7435

To: martinvonz, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1824,7 +1824,6 @@ 
 
 
 datapath = resourceutil.datapath
-i18n.setdatapath(datapath)
 
 
 def checksignature(func):
diff --git a/mercurial/i18n.py b/mercurial/i18n.py
--- a/mercurial/i18n.py
+++ b/mercurial/i18n.py
@@ -13,6 +13,7 @@ 
 import sys
 
 from .pycompat import getattr
+from .utils import resourceutil
 from . import (
     encoding,
     pycompat,
@@ -45,18 +46,14 @@ 
         # ctypes not found or unknown langid
         pass
 
-_ugettext = None
 
-
-def setdatapath(datapath):
-    datapath = pycompat.fsdecode(datapath)
-    localedir = os.path.join(datapath, 'locale')
-    t = gettextmod.translation('hg', localedir, _languages, fallback=True)
-    global _ugettext
-    try:
-        _ugettext = t.ugettext
-    except AttributeError:
-        _ugettext = t.gettext
+datapath = pycompat.fsdecode(resourceutil.datapath)
+localedir = os.path.join(datapath, 'locale')
+t = gettextmod.translation('hg', localedir, _languages, fallback=True)
+try:
+    _ugettext = t.ugettext
+except AttributeError:
+    _ugettext = t.gettext
 
 
 _msgcache = {}  # encoding: {message: translation}
diff --git a/doc/gendoc.py b/doc/gendoc.py
--- a/doc/gendoc.py
+++ b/doc/gendoc.py
@@ -26,11 +26,7 @@ 
 from mercurial import demandimport
 
 demandimport.enable()
-# Load util so that the locale path is set by i18n.setdatapath() before
-# calling _().
-from mercurial import util
 
-util.datapath
 from mercurial import (
     commands,
     encoding,