翻译用Glade和Python编写的GTK UI
我花了一些时间四处寻找答案,我有很多答案。理论上,我的代码应该可以工作,但是它不能。 首先我将发布最小的代码,然后我将描述问题 test.glade:翻译用Glade和Python编写的GTK UI,python,translation,pygtk,glade,pygobject,Python,Translation,Pygtk,Glade,Pygobject,我花了一些时间四处寻找答案,我有很多答案。理论上,我的代码应该可以工作,但是它不能。 首先我将发布最小的代码,然后我将描述问题 test.glade: <?xml version="1.0" encoding="UTF-8"?> <interface> <!-- interface-requires gtk+ 3.0 --> <object class="GtkWindow" id="window"> <property na
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window">
<property name="can_focus">False</property>
<property name="window_position">center-always</property>
<property name="default_width">400</property>
<signal name="destroy" handler="main_quit" swapped="no"/>
<child>
<object class="GtkBox" id="box1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">File</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Edit</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Find</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">View</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Document</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
en.po:
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-06-15 15:18+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: test.glade:66
msgid "Document"
msgstr "Dokumentumok"
#: test.glade:30
msgid "Edit"
msgstr "Szerkesztés"
#: test.glade:18
msgid "File"
msgstr "Fájl"
#: test.glade:42
msgid "Find"
msgstr "Keresés"
#: test.glade:54
msgid "View"
msgstr "Nézet"
图形用户界面:
我在Gnome桌面上使用Ubuntu20.04,系统语言是目标语言hu_hu当我使用正确的编码代替en.po-ie.UTF-8中的单词字符集时,代码对我来说是有效的 顺便说一句: 当我在控制台/终端中使用时
msgfmt -c en.po -o myapp.mo
然后它甚至显示警告
en.po: warning: Charset "CHARSET" is not a portable encoding name.
Message conversion to user's charset might not work.
它确认了必须更改字符集
它还显示其他值的警告-软件包版本、YEAR-MO-DA HO:MI+区域、全名、语言
-但它们并不那么重要
po/en.po:7: warning: header field 'Project-Id-Version' still has the initial default value
po/en.po:7: warning: header field 'PO-Revision-Date' still has the initial default value
po/en.po:7: warning: header field 'Last-Translator' still has the initial default value
po/en.po:7: warning: header field 'Language-Team' still has the initial default value
po/en.po:7: warning: header field 'Language' still has the initial default value
编辑:
代码似乎设置了LC_ALL-locale.setlocalelocale.LC_ALL。。。但在我基于Ubuntu18.04的Linux Mint 19.2系统中,我也有LANG=pl\u pl.UTF-8,LANGUAGE=pl\u pl:pl,这可能会有所不同。但是我不能在代码locale.setlocalelocale.LANG中设置它
编辑:
您确认了变量语言是问题所在
如果语言是hu:en或hu,则.mo文件必须位于文件夹hu中,而不是hu\u hu中
顺便说一句:
我检查了/usr/share/locale/中是否也有hu文件夹,但当我运行时
locale -a | grep hu
然后它告诉我
hu_HU
hu_HU.UTF-8
和locale.setlocalelocale.LC_ALL,'hu'给我错误,但locale.setlocalelocale.LC_ALL,'hu_-hu'运行时没有错误
我创建了两个不同单词的文件夹mo/hu\u hu/。。。和mo/pl_pl/。。。即使我使用locale.setlocalelocale.LC_ALL,“hu_-hu”我也能看到pl_-pl中的单词。但是当我删除locale.setlocale时,我会看到英语单词
要查看胡胡胡的话,我必须在控制台中运行它
LANGUAGE=hu_HU python test.py
至于我,在字符集的位置上,你应该输入一些正确的值——例如UTF-8——内容类型:text/plain;字符集=UTF-8\n。Word字符集的值不正确。谢谢!我真的很傻。。。现在,这个示例至少可以运行了,但它产生了与实际程序相同的问题:GUI仍然是英文的。更新了要显示的问题。请检查print locale.getlocale中的内容。如果你得到en_GB,那么你必须把它放在mo/en_GB/LC_MESSAGES/myapp.mo我得到pl_pl,我必须放在mo/pl_pl/LC_MESSAGES/myapp.moI在locale.getlocale输出中有'hu_hu','UTF-8',因为这是系统语言。打印输出的翻译没有问题。所以这就是我的问题:一切看起来都很完美,但仍然不起作用。。。但在我基于Ubuntu18.04的Linux Mint 19.2系统中,我也有LANG=pl\u pl.UTF-8,LANGUAGE=pl\u pl:pl,这可能会有所不同。但是我不能在代码locale.setlocalelocale.LANG中设置它,…顺便说一句:我发现了一些信息,Gtk.Builder可能需要在系统中进行一些额外的设置,而gettext.gettext不需要这些设置。
locale -a | grep hu
hu_HU
hu_HU.UTF-8
LANGUAGE=hu_HU python test.py