3232import optparse
3333import os
3434import sys
35- from locale import LC_ALL , getpreferredencoding , setlocale
35+ from locale import getpreferredencoding
3636
3737import gobject
3838import gtk
3939import pango
4040from pygments .lexers import PythonLexer
4141
42- from bpython import importcompletion , repl
42+ from bpython import importcompletion , repl , translations
4343from bpython .formatter import theme_map
44+ from bpython .translations import _
4445import bpython .args
4546
47+
4648py3 = 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
8789class 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
765769def 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
0 commit comments