简体   繁体   English

gtk 的 python 语言环境在 windows 上不起作用

[英]python locale for gtk does not work on windows

I have python 2.7 and pygtk.我有 python 2.7 和 pygtk。 I am trying to set locale language for gtk in my application but no luck.我正在尝试在我的应用程序中为 gtk 设置区域设置语言,但没有运气。 My windows is in slovak language and I would like to have button labels in my app in english.我的 windows 是斯洛伐克语,我想在我的应用程序中有英文的按钮标签。 How to solve it?如何解决?

I tried this but no luck (all labels are still in slovak):我试过了,但没有运气(所有标签仍然是斯洛伐克语):

 import os os.environ['LANGUAGE'] = 'en_US' #tried en_UK as well os.environ['LANG'] = 'en_US' os.putenv('en_US', 'LANG') import locale locale.setlocale(locale.LC_ALL, 'English_United Kingdom.1252' )

but when I make cmd file this works:但是当我制作 cmd 文件时,它可以工作:


    set LANG=en_US
    something.exe 

what am I doing wrong?我究竟做错了什么?

This is becoming a common question these days and should probably become a PyGTK FAQ.这些天来,这已成为一个常见问题,并且可能应该成为 PyGTK 常见问题解答。 See for example this PyGTK bug report参见例如这个 PyGTK错误报告

In short, there's a whole lot of details you're missing.简而言之,您缺少很多细节。 For example:例如:

1) Starting with Python 2.4, on Windows, assigning values to os.environ only changes the copy of the environment variables Python manages and no longer has any effect on the copy maintained by the C library (msvcr90 for Python, msvcrt for the various GTK+ related dll's). 1) Starting with Python 2.4, on Windows, assigning values to os.environ only changes the copy of the environment variables Python manages and no longer has any effect on the copy maintained by the C library (msvcr90 for Python, msvcrt for the various GTK+相关的dll)。

2) Once you take care of the above you also need to take special care of configuring libintl. 2) 完成上述操作后,您还需要特别注意配置 libintl。 That means you'll need to bindtextdomain() and bind_textdomain_codeset() both intl.dll and Python's gettext module.这意味着您需要 bindtextdomain() 和 bind_textdomain_codeset() intl.dll 和 Python 的 gettext 模块。

There's probably more that I don't remember right now, but you could take a look at myelib.intl module written specifically for what you're trying to do (and more).我现在可能不记得还有更多内容,但是您可以查看我的elib.intl模块,该模块专门针对您正在尝试做的事情(以及更多内容)编写。 When you have it working, you can simply set the LANGUAGE environment variable to C to have the default American English.当您使用它时,您只需将 LANGUAGE 环境变量设置为 C 即可使用默认的美式英语。

You can do that either from a.bat or.cmd file or by using os.environ['LANGUAGE'] = 'C' befory you import elib.intl.您可以在导入 elib.intl 之前从 a.bat 或 .cmd 文件或使用 os.environ['LANGUAGE'] = 'C' 来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM