gtk的python语言环境在windows上不起作用 [英] python locale for gtk does not work on windows

查看:141
本文介绍了gtk的python语言环境在windows上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有python 2.7和pygtk。我正在尝试在我的应用程序中为gtk设置语言环境语言,但没有运气。我的窗户是斯洛伐克语言,我希望在我的应用程序中有英文按钮标签。如何解决它?



我试过这个,但没有运气(所有标签仍然在斯洛伐克):

  import os 
os.environ ['LANGUAGE'] ='en_US'#tried en_UK以及
os.environ [ 'LANG'] ='en_US'
os.putenv('en_US','LANG')
导入区域设置
locale.setlocale(locale.LC_ALL,'English_United Kingdom.1252')



但是当我使cmd文件这个工程:

 

set LANG = en_US
something.exe

我在做什么错?

解决方案

这些日子已成为常见问题,应该可能成为PyGTK FAQ。
请参阅此PyGTK



总之,您错过了很多细节。例如:1)从Python 2.4开始,在Windows上,为os.environ赋值只有
会更改Python管理的环境变量的副本,并且不会更长的
对由C库维护的副本产生任何影响(对于Python,msvcr90,对于各种GTK +相关的dll,msvcrt
)。

2 )一旦你处理了上述内容,你还需要特别注意
配置libintl。这意味着你需要绑定textdomain()和
bind_textdomain_codeset()intl.dll和Python的gettext模块。



可能还有更多我不现在请记住,但你可以在我的 =nofollow> elib.intl 模块专门为你想要的
做(和更多)。当你有它的工作,你可以简单地将语言
环境变量设置为C以具有默认的美国英语。



你可以这样做
无论是从.bat还是.cmd文件,或者使用os.environ ['LANGUAGE'] ='C'befory
导入elib.intl。


I have python 2.7 and pygtk. I am trying to set locale language for gtk in my application but no luck. My windows is in slovak language and I would like to have button labels in my app in english. 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:


    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. See for example this PyGTK bug report

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).

2) Once you take care of the above you also need to take special care of configuring libintl. That means you'll need to bindtextdomain() and bind_textdomain_codeset() both intl.dll and Python's gettext module.

There's probably more that I don't remember right now, but you could take a look at my elib.intl module written specifically for what you're trying to do (and more). When you have it working, you can simply set the LANGUAGE environment variable to C to have the default American English.

You can do that either from a .bat or .cmd file or by using os.environ['LANGUAGE'] = 'C' befory you import elib.intl.

这篇关于gtk的python语言环境在windows上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆