2012-11-15 54 views
6

我的系統(Linux)的缺省語言環境 - en_US。當我將locale更改爲俄語(LANG = ru_RU ./show_form.py)時,python字符串「hello to me」在英文中正確顯示(在控制檯中),其他(glade格式)。 (LANG = ru_RU.utf-8 ./show_form.py - 結果相同)。pygtk + glade + localization

我在做什麼錯?

我有例如(show_form.py)簡單的Python代碼:

#!/usr/bin/env python 
# -*- coding: utf-8 -*- 

import pygtk, gtk, gtk.glade 
import locale, gettext 

APP="show_form" 
DIR="locale" 

locale.setlocale(locale.LC_ALL, '') 
gettext.bindtextdomain(APP, DIR) 
gettext.textdomain(APP) 
lang = gettext.translation(APP, DIR) 
_ = lang.gettext 
gettext.install(APP, unicode=False, codeset='utf-8', localedir=DIR) 
print _("hello to me") 

wTree = gtk.glade.XML("localize.glade") 
gtk.glade.bindtextdomain(APP, DIR) 

window = wTree.get_widget("window1") 
window.connect("delete_event", lambda wid, we: gtk.main_quit()) 
window.show_all() 
gtk.main() 

和文件的.mo一些。語言。 .po文件如下:

# Russian translations for PACKAGE package.          
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER        
# This file is distributed under the same license as the PACKAGE package.  
# <[email protected]>, 2012.               
# 
msgid "" 
msgstr "" 
"Project-Id-Version: PACKAGE VERSION\n" 
"Report-Msgid-Bugs-To: \n" 
"POT-Creation-Date: 2012-11-14 13:54+0300\n" 
"PO-Revision-Date: 2012-11-14 13:58+0300\n" 
"Last-Translator: <[email protected]>\n" 
"Language-Team: Russian\n" 
"Language: ru\n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=utf-8\n" 
"Content-Transfer-Encoding: 16bit\n" 
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" 
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" 

#: show_form.py:14 
msgid "hello to me" 
msgstr "привет мне" 

#: localize.glade.h:1 
msgid "label text" 
msgstr "метка" 

#: localize.glade.h:2 
msgid "button text" 
msgstr "кнопка" 

#: localize.glade.h:3 
msgid "checkbutton text" 
msgstr "галочка" 

和en_US文件(像這與不同的msgstr)。和小標題,按鈕,複選框的空地格式。

UPD:

我的.mo文件創建的字符串:

intltool-extract --type=gettext/glade localize.glade 

xgettext --language=Python --keyword=_ --keyword=N_ --output=show_form.pot show_form.py localize.glade.h 

msginit --locale=ru --input=show_form.pot 
msginit --locale=en_US --input=show_form.pot 
msginit --locale=de_DE --input=show_form.pot 

我糾正.po文件後這一點。

,並在結尾:

msgfmt ru.po -o locale/ru/LC_MESSAGES/show_form.mo 
msgfmt en_US.po -o locale/en_US/LC_MESSAGES/show_form.mo 
msgfmt de.po -o locale/de/LC_MESSAGES/show_form.mo 

UPD2:解決方案

-wTree = gtk.glade.XML("localize.glade") 
gtk.glade.bindtextdomain(APP, DIR) 
+wTree = gtk.glade.XML("localize.glade", "window1", APP) 

回答

1

您需要使用intltool翻譯您格萊德文件。

+1

明天我會將我的.mo文件創建命令添加到章節「Upd:」 –

+0

正如你可能看到我使用intltool,但這沒有幫助。 –

+0

我相信,您還必須將翻譯翻譯回glade文件。 – ptomato