X Tutup
Skip to content

Commit 5361e2b

Browse files
committed
i18n: merge from Trundle repo.
1 parent 4513414 commit 5361e2b

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

bpython/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import unicodedata
3838
import errno
3939

40-
from locale import LC_ALL, setlocale
4140
import locale
4241
from types import ModuleType
4342

@@ -58,6 +57,7 @@
5857
from bpython.keys import key_dispatch
5958

6059
# This for i18n
60+
from bpython import translations
6161
from bpython.translations import _
6262

6363
from bpython import repl
@@ -1736,7 +1736,7 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
17361736
def main(args=None, locals_=None, banner=None):
17371737
global stdscr
17381738

1739-
setlocale(LC_ALL, '')
1739+
translations.init()
17401740

17411741
config, options, exec_args = bpython.args.parse(args)
17421742

bpython/gtk_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
import optparse
3333
import os
3434
import sys
35-
from locale import LC_ALL, getpreferredencoding, setlocale
35+
from locale import getpreferredencoding
3636

3737
import gobject
3838
import gtk
3939
import pango
4040
from pygments.lexers import PythonLexer
4141

42-
from bpython import importcompletion, repl
42+
from bpython import importcompletion, repl, translations
4343
from bpython.formatter import theme_map
4444
from bpython.translations import _
4545
import bpython.args
@@ -767,7 +767,7 @@ def init_import_completion():
767767

768768

769769
def main(args=None):
770-
setlocale(LC_ALL, '')
770+
translations.init()
771771

772772
gtk_options = (_('gtk-specific options'),
773773
_("Options specific to bpython's Gtk+ front end"),

bpython/translations/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import os.path
21
import gettext
2+
from sys import version_info
33

4-
try:
5-
translation = gettext.translation('bpython')
6-
except IOError:
7-
# try to load .mo files created with babel on i18n/ dir
8-
try:
9-
translation = gettext.translation('bpython', 'i18n')
10-
except IOError:
11-
translation = None
124

13-
if translation is None:
14-
def _(s):
15-
return s
5+
translator = None
6+
7+
if version_info >= (3, 0):
8+
def _(message):
9+
return translator.gettext(message)
1610
else:
17-
_ = translation.ugettext
11+
def _(message):
12+
return translator.ugettext(message)
13+
14+
15+
def init(locale_dir=None, languages=None):
16+
global translator
17+
translator = gettext.translation('bpython', locale_dir, languages,
18+
fallback=True)
19+
20+
init()

bpython/urwid.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
from pygments.token import Token
4646

47-
from bpython import args as bpargs, repl
47+
from bpython import args as bpargs, repl, translations
4848
from bpython.formatter import theme_map
4949
from bpython.importcompletion import find_coroutine
5050
from bpython.translations import _
@@ -859,9 +859,7 @@ def tab(self, back=False):
859859
self._completion_update_suppressed = False
860860

861861
def main(args=None, locals_=None, banner=None):
862-
# Err, somewhat redundant. There is a call to this buried in urwid.util.
863-
# That seems unfortunate though, so assume that's going away...
864-
locale.setlocale(locale.LC_ALL, '')
862+
translations.init()
865863

866864
# TODO: maybe support displays other than raw_display?
867865
config, options, exec_args = bpargs.parse(args, (

0 commit comments

Comments
 (0)
X Tutup