X Tutup
Skip to content

Commit 91cf334

Browse files
committed
Merge in Michele's changes.
2 parents ebf792c + 4880ebf commit 91cf334

File tree

8 files changed

+296
-50
lines changed

8 files changed

+296
-50
lines changed

bpython/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
# THE SOFTWARE.
2222

23+
import os.path
2324

2425
__version__ = '0.9.7.1'
26+
package_dir = os.path.abspath(os.path.dirname(__file__))
2527

2628

2729
def embed(locals_=None, args=['-i', '-q'], banner=None):

bpython/cli.py

Lines changed: 11 additions & 8 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

@@ -57,6 +56,10 @@
5756
# This for keys
5857
from bpython.keys import key_dispatch
5958

59+
# This for i18n
60+
from bpython import translations
61+
from bpython.translations import _
62+
6063
from bpython import repl
6164
from bpython.pager import page
6265
import bpython.args
@@ -247,7 +250,7 @@ def confirm(self, q):
247250
except ValueError:
248251
return False
249252

250-
return reply.lower() in ('y', 'yes')
253+
return reply.lower() in (_('y'), _('yes'))
251254

252255

253256
def notify(self, s, n=10):
@@ -880,7 +883,7 @@ def p_key(self, key):
880883
TerminalFormatter())
881884
page(source)
882885
else:
883-
self.statusbar.message('Cannot show source.')
886+
self.statusbar.message(_('Cannot show source.'))
884887
return ''
885888

886889
elif key == '\n':
@@ -1530,10 +1533,10 @@ def init_wins(scr, colors, config):
15301533
# problems that needed dirty hackery to fix. :)
15311534

15321535
statusbar = Statusbar(scr, main_win, background, config,
1533-
" <%s> Rewind <%s> Save <%s> Pastebin <%s> Pager <%s> Show Source " %
1534-
(config.undo_key, config.save_key,
1535-
config.pastebin_key, config.last_output_key,
1536-
config.show_source_key),
1536+
_(" <%s> Rewind <%s> Save <%s> Pastebin "
1537+
" <%s> Pager <%s> Show Source ") %
1538+
(config.undo_key, config.save_key, config.pastebin_key,
1539+
config.last_output_key, config.show_source_key),
15371540
get_colpair(config, 'main'))
15381541

15391542
return main_win, statusbar
@@ -1733,7 +1736,7 @@ def main_curses(scr, args, config, interactive=True, locals_=None,
17331736
def main(args=None, locals_=None, banner=None):
17341737
global stdscr
17351738

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

17381741
config, options, exec_args = bpython.args.parse(args)
17391742

bpython/gtk_.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@
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
44+
from bpython.translations import _
4445
import bpython.args
4546

47+
4648
py3 = sys.version_info[0] == 3
4749

4850
_COLORS = dict(b='blue', c='cyan', g='green', m='magenta', r='red',
@@ -85,14 +87,16 @@ def formatvalue(self, value):
8587

8688

8789
class ExceptionDialog(gtk.MessageDialog):
88-
def __init__(self, exc_type, exc_value, tb, text='An error occurred.'):
90+
def __init__(self, exc_type, exc_value, tb, text=None):
91+
if text is None:
92+
text = _('An error occurred.')
8993
gtk.MessageDialog.__init__(self, buttons=gtk.BUTTONS_CLOSE,
9094
type=gtk.MESSAGE_ERROR,
9195
message_format=text)
9296
self.set_resizable(True)
9397
import cgitb
9498
text = cgitb.text((exc_type, exc_value, tb), 5)
95-
expander = gtk.Expander('Exception details')
99+
expander = gtk.Expander(_('Exception details'))
96100
self.vbox.pack_start(expander)
97101
textview = gtk.TextView()
98102
textview.get_buffer().set_text(text)
@@ -108,9 +112,9 @@ class ExceptionManager(object):
108112
the exception's type, value, a traceback and a text to display as
109113
arguments.
110114
"""
111-
def __init__(self, DialogType, text='An error occurred.'):
115+
def __init__(self, DialogType, text=None):
112116
self.DialogType = DialogType
113-
self.text = text
117+
self.text = text or _('An error occurred.')
114118

115119
def __enter__(self):
116120
return self
@@ -144,7 +148,7 @@ class Statusbar(gtk.Statusbar):
144148
"""Contains feedback messages"""
145149
def __init__(self):
146150
gtk.Statusbar.__init__(self)
147-
self.context_id = self.get_context_id('Statusbar')
151+
self.context_id = self.get_context_id(_('Statusbar'))
148152

149153
def message(self, s, n=3):
150154
self.clear()
@@ -221,7 +225,7 @@ def do_expose_event(self, event):
221225
width, height = self.get_size()
222226
self.style.paint_flat_box(self.window, gtk.STATE_NORMAL,
223227
gtk.SHADOW_OUT, None, self,
224-
'tooltip', 0, 0, width, height)
228+
_('tooltip'), 0, 0, width, height)
225229
gtk.Window.do_expose_event(self, event)
226230

227231
def forward(self):
@@ -290,7 +294,7 @@ def confirm(self, q):
290294
return response == gtk.RESPONSE_YES
291295

292296
def file_prompt(self, s):
293-
chooser = gtk.FileChooserDialog(title="File to save to",
297+
chooser = gtk.FileChooserDialog(title=_("File to save to"),
294298
action=gtk.FILE_CHOOSER_ACTION_SAVE,
295299
buttons=(gtk.STOCK_CANCEL,
296300
gtk.RESPONSE_CANCEL,
@@ -301,12 +305,12 @@ def file_prompt(self, s):
301305
chooser.set_current_folder(os.path.expanduser('~'))
302306

303307
pyfilter = gtk.FileFilter()
304-
pyfilter.set_name("Python files")
308+
pyfilter.set_name(_("Python files"))
305309
pyfilter.add_pattern("*.py")
306310
chooser.add_filter(pyfilter)
307311

308312
allfilter = gtk.FileFilter()
309-
allfilter.set_name("All files")
313+
allfilter.set_name(_("All files"))
310314
allfilter.add_pattern("*")
311315
chooser.add_filter(allfilter)
312316

@@ -477,7 +481,7 @@ def do_key_press_event(self, event):
477481
show_source_in_new_window(source, self.config.color_gtk_scheme,
478482
self.config.syntax)
479483
else:
480-
self.interact.notify('Cannot show source.')
484+
self.interact.notify(_('Cannot show source.'))
481485
elif event.keyval == gtk.keysyms.Return:
482486
if self.list_win_visible:
483487
self.list_win_visible = False
@@ -763,13 +767,12 @@ def init_import_completion():
763767

764768

765769
def main(args=None):
770+
translations.init()
766771

767-
setlocale(LC_ALL, '')
768-
769-
gtk_options = ('gtk-specific options',
770-
"Options specific to bpython's Gtk+ front end",
772+
gtk_options = (_('gtk-specific options'),
773+
_("Options specific to bpython's Gtk+ front end"),
771774
[optparse.Option('--socket-id', dest='socket_id',
772-
type='int', help='Embed bpython')])
775+
type='int', help=_('Embed bpython'))])
773776
config, options, exec_args = bpython.args.parse(args, gtk_options,
774777
True)
775778

@@ -825,7 +828,7 @@ def main(args=None):
825828
pastebin.connect("activate", repl_widget.do_paste)
826829
filemenu.append(pastebin)
827830

828-
pastebin_partial = gtk.MenuItem("Pastebin selection")
831+
pastebin_partial = gtk.MenuItem(_("Pastebin selection"))
829832
pastebin_partial.connect("activate", repl_widget.do_partial_paste)
830833
filemenu.append(pastebin_partial)
831834

bpython/translations/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import gettext
2+
import os.path
3+
from sys import version_info
4+
5+
from bpython import package_dir
6+
7+
translator = None
8+
9+
if version_info >= (3, 0):
10+
def _(message):
11+
return translator.gettext(message)
12+
else:
13+
def _(message):
14+
return translator.ugettext(message)
15+
16+
17+
def init(locale_dir=None, languages=None):
18+
global translator
19+
if locale_dir is None:
20+
locale_dir = os.path.join(package_dir, 'translations')
21+
22+
translator = gettext.translation('bpython', locale_dir, languages,
23+
fallback=True)
24+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Translations template for bpython.
2+
# Copyright (C) 2010 ORGANIZATION
3+
# This file is distributed under the same license as the bpython project.
4+
# Claudia Medde, 2010.
5+
#
6+
#,
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: bpython 0.9.7\n"
10+
"Report-Msgid-Bugs-To: http://bitbucket.org/bobf/bpython/issues\n"
11+
"POT-Creation-Date: 2010-07-21 14:46+0200\n"
12+
"PO-Revision-Date: 2010-07-21 14:46+0200\n"
13+
"Last-Translator: Claudia Medde\n"
14+
"Language-Team: bpython developers\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=utf-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Generated-By: Babel 0.9.5\n"
19+
20+
21+
#: bpython/cli.py:250 bpython/urwid.py:400
22+
msgid "y"
23+
msgstr "s"
24+
25+
#: bpython/cli.py:250 bpython/urwid.py:400
26+
msgid "yes"
27+
msgstr "si"
28+
29+
#: bpython/cli.py:877 bpython/gtk_.py:482
30+
msgid "Cannot show source."
31+
msgstr "Imposible mostrar el código fuente"
32+
33+
#: bpython/cli.py:1527 bpython/urwid.py:415
34+
msgid " <%s> Rewind <%s> Save <%s> Pastebin <%s> Pager <%s> Show Source "
35+
msgstr " <%s> Rewind <%s> Salva <%s> Pastebin <%s> Pager <%s> Mostra el código fuente"
36+
37+
#: bpython/gtk_.py:90 bpython/gtk_.py:113
38+
msgid "An error occurred."
39+
msgstr ""
40+
41+
#: bpython/gtk_.py:97
42+
msgid "Exception details"
43+
msgstr ""
44+
45+
#: bpython/gtk_.py:149
46+
msgid "Statusbar"
47+
msgstr "Statusbar"
48+
49+
#: bpython/gtk_.py:226
50+
msgid "tooltip"
51+
msgstr "tooltip"
52+
53+
#: bpython/gtk_.py:295
54+
msgid "File to save to"
55+
msgstr ""
56+
57+
#: bpython/gtk_.py:306
58+
msgid "Python files"
59+
msgstr "Files Python"
60+
61+
#: bpython/gtk_.py:311
62+
msgid "All files"
63+
msgstr "Todos los files"
64+
65+
#: bpython/gtk_.py:773
66+
msgid "gtk-specific options"
67+
msgstr ""
68+
69+
#: bpython/gtk_.py:774
70+
msgid "Options specific to bpython's Gtk+ front end"
71+
msgstr ""
72+
73+
#: bpython/gtk_.py:776
74+
msgid "Embed bpython"
75+
msgstr "Embed bpython"
76+
77+
#: bpython/gtk_.py:832
78+
msgid "Pastebin selection"
79+
msgstr "Pastebin la selección"
80+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Translations template for bpython.
2+
# Copyright (C) 2010 bpython developers
3+
# This file is distributed under the same license as the bpython project.
4+
# Michele Orrù <maker.py@gmail.com>, 2010.
5+
#
6+
#,
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: bpython 0.9.7\n"
10+
"Report-Msgid-Bugs-To: http://bitbucket.org/bobf/bpython/issues\n"
11+
"POT-Creation-Date: 2010-07-21 13:52+0200\n"
12+
"PO-Revision-Date: 2010-07-21 13:53+0200\n"
13+
"Last-Translator: Michele Orrù\n"
14+
"Language-Team: Michele Orrù\n"
15+
"MIME-Version: 1.0\n"
16+
"Content-Type: text/plain; charset=utf-8\n"
17+
"Content-Transfer-Encoding: 8bit\n"
18+
"Generated-By: Babel 0.9.5\n"
19+
20+
#: bpython/cli.py:250 bpython/urwid.py:400
21+
msgid "y"
22+
msgstr "s"
23+
24+
#: bpython/cli.py:250 bpython/urwid.py:400
25+
msgid "yes"
26+
msgstr "si"
27+
28+
#: bpython/cli.py:877 bpython/gtk_.py:482
29+
msgid "Cannot show source."
30+
msgstr "Non è possibile mostrare il codice sorgente"
31+
32+
#: bpython/cli.py:1527 bpython/urwid.py:415
33+
#, python-format
34+
msgid " <%s> Rewind <%s> Save <%s> Pastebin <%s> Pager <%s> Show Source "
35+
msgstr " <%s> Rewind <%s> Salva <%s> Pastebin <%s> Pager <%s> Mostra Sorgente"
36+
37+
#: bpython/gtk_.py:90 bpython/gtk_.py:113
38+
msgid "An error occurred."
39+
msgstr "È stato riscontrato un errore"
40+
41+
#: bpython/gtk_.py:97
42+
msgid "Exception details"
43+
msgstr "Dettagli sull'eccezione"
44+
45+
#: bpython/gtk_.py:149
46+
msgid "Statusbar"
47+
msgstr "Barra di stato"
48+
49+
#: bpython/gtk_.py:226
50+
msgid "tooltip"
51+
msgstr "tooltip"
52+
53+
#: bpython/gtk_.py:295
54+
msgid "File to save to"
55+
msgstr "File nel quale salvare"
56+
57+
#: bpython/gtk_.py:306
58+
msgid "Python files"
59+
msgstr "Files python"
60+
61+
#: bpython/gtk_.py:311
62+
msgid "All files"
63+
msgstr "Tutti i files"
64+
65+
#: bpython/gtk_.py:773
66+
msgid "gtk-specific options"
67+
msgstr "Opzioni specifiche di gtk"
68+
69+
#: bpython/gtk_.py:774
70+
msgid "Options specific to bpython's Gtk+ front end"
71+
msgstr "Opzioni specifiche riguardo il frontend gtk+ di bpython"
72+
73+
#: bpython/gtk_.py:776
74+
msgid "Embed bpython"
75+
msgstr ""
76+
77+
#: bpython/gtk_.py:832
78+
msgid "Pastebin selection"
79+
msgstr ""
80+

0 commit comments

Comments
 (0)
X Tutup