Pregunta

I'm building a multi lingual application in python, but when I use the gtk.BUTTONS_YES_NO, it always show only "YES" or "NO", how can I set the text to be, YES, SIM, SI or any other string?

dialog = gtk.MessageDialog(self, gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, txt_sendingToDevice)
dialog.format_secondary_text(txt_confirmSendToDevice)
response = dialog.run()
dialog.destroy()

Thank you!

¿Fue útil?

Solución

Assuming you only use stock buttons and you have installed support for the locale that you want to display, under Linux you can run this:

import gtk
dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, 
        gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Hello world")
response = dialog.run()
dialog.destroy()

Starting with:

LC_ALL='sv_SE.utf8' python test.py

should display, "Nej" and "Ja" buttons (Swedish). And:

LC_ALL='en_US.utf8' python test.py

should display, "No" and "Yes" buttons.

You can also set this explicit in code:

import gtk
import locale
locale.setlocale(locale.LC_ALL, 'sv_SE.utf8')
dialog = gtk.MessageDialog(None, gtk.DIALOG_DESTROY_WITH_PARENT, 
        gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Hello world")
response = dialog.run()
dialog.destroy()

Prerequisites

Install the appropriate language pack, e.g. in this case Swedish (sv):

sudo apt-get install language-pack-sv language-pack-gnome-sv
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top