如何为 pyGTK 使用我自己的语言环境?
我正在使用 pyGTK 编写一个软件。 我想知道如何强制 pyGTK 使用我自己的 GTK *.mo 文件。
事实上我的问题是,我在Linux下编码,但我想在Windows下分发它。为了获得 Windows 可执行文件,我使用 cx_Freeze,我可以在文本中包含我自己的 gettext,并且效果很好,但我也想包含 pyGTK gettext,因为如果我不这样做,按钮上的文本仍然是英文,即使Windows 使用不同的语言。由于我不想支持所有 GTK 语言,所以我不想包含所有语言。
预先感谢并抱歉英语不好......
编辑: 因为代码片段比任何东西都好:
APP_NAME="MyWonderfulApp"
LOCALE_DIR="locale"
#Translation stuff
local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
langs = []
lc, encoding = locale.getdefaultlocale()
if (lc):
langs = [lc]
language = os.environ.get('LANGUAGE', None)
if (language):
langs += language.split(":")
langs += ["fr_FR", "en_US"]
gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
gettext.textdomain(APP_NAME)
lang = gettext.translation(APP_NAME, LOCALE_DIR, languages=langs, fallback = True)
_ = lang.gettex
I'm writing a soft using pyGTK.
I'd like to know how to force pyGTK to use my own *.mo files for GTK.
In fact my problem is, I code under Linux but I want to distribute it under Windows. To get a Windows executable, I use cx_Freeze, I can include my own gettext for my texts and it's work well, but I want to include pyGTK gettext too, because if I don't to that text on button are still in English even the Windows is in different language. And since I don't want to support all GTK languages, I don't want to includes all languages.
Thanks in advance and sorry for the bad english...
EDiT:
Since a code snippet is better than anything:
APP_NAME="MyWonderfulApp"
LOCALE_DIR="locale"
#Translation stuff
local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
langs = []
lc, encoding = locale.getdefaultlocale()
if (lc):
langs = [lc]
language = os.environ.get('LANGUAGE', None)
if (language):
langs += language.split(":")
langs += ["fr_FR", "en_US"]
gettext.bindtextdomain(APP_NAME, LOCALE_DIR)
gettext.textdomain(APP_NAME)
lang = gettext.translation(APP_NAME, LOCALE_DIR, languages=langs, fallback = True)
_ = lang.gettex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正确初始化了 Python 的 gettext,但未正确初始化所使用的 libintl
由 GTK+ 和朋友们制作。你可以看看我的 elib.intl< /a> 模块看看如何
完成了。
You're initializing Python's gettext correctly, but not libintl which is used
by GTK+ and friends. You could take a look at my elib.intl module to see how
that's done.