首页 文章

如何在OSX Mountain Lion中为应用程序包设置默认语言环境

提问于
浏览
1

如何设置OS X Mountain Lion中运行应用程序的默认语言环境(LANG,LC_ALL = en_US.UTF-8)?

我正在尝试使用py2app运行打包到.app的Python程序 . 通过双击代码段来运行应用程序时

import locale
print locale.getlocale()

返回(无,无)

但是,通过执行从终端运行应用程序时

opensesame.app/Contents/MacOS/opensesame

getlocale()函数正确返回(en_US,UTF-8)
(由于终端具有正确的环境设置)

我发现,当双击时,应用程序在不同的环境中运行,而不是从终端运行时,所以现在我正在尝试为应用程序设置默认的编码变量 .

我已经尝试了我发现的建议:How can you get the system default language/locale, in a py2app packaged Python app on Mac OS X?并按照以下说明操作:http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPInternational/Articles/ChoosingLocalizations.html

我已将CFBundleLocalizations和LSEnvironment键添加到应用程序包内的Info.plist(下面发布),但getlocale()函数保持returing(None,None)

任何人都可以告诉我为OS X应用程序正确设置这些变量,以便Python选择这些吗?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleDisplayName</key>
    <string>opensesame</string>
    <key>CFBundleExecutable</key>
    <string>opensesame</string>
    <key>CFBundleIconFile</key>
    <string>opensesame.icns</string>
    <key>CFBundleIdentifier</key>
    <string>org.pythonmac.unspecified.opensesame</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>opensesame</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>0.0.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>0.0.0</string>
    <key>CFBundleLocalizations</key>
    <string>en_US.UTF-8</string>
    <key>LSHasLocalizedDisplayName</key>
    <false/>
    <key>NSAppleScriptEnabled</key>
    <false/>
    <key>NSHumanReadableCopyright</key>
    <string>Copyright not specified</string>
    <key>NSMainNibFile</key>
    <string>MainMenu</string>
    <key>NSPrincipalClass</key>
    <string>NSApplication</string>
    <key>LSEnvironment</key>
    <dict>
        <key>LANG</key>
        <string>en_US.UTF-8</string>
        <key>LC_ALL</key>
        <string>en_US.UTF-8</string>
    </dict>
    <key>PyMainFileNames</key>
    <array>
        <string>__boot__</string>
    </array>
    <key>PyOptions</key>
    <dict>
        <key>alias</key>
        <false/>
        <key>argv_emulation</key>
        <false/>
        <key>emulate_shell_environment</key>
        <false/>
        <key>no_chdir</key>
        <false/>
        <key>prefer_ppc</key>
        <false/>
        <key>site_packages</key>
        <false/>
        <key>use_pythonpath</key>
        <false/>
    </dict>
    <key>PyResourcePackages</key>
    <array/>
    <key>PyRuntimeLocations</key>
    <array>
        <string>@executable_path/../Frameworks/Python.framework/Versions/2.7/Python</string>
    </array>
    <key>PythonInfoDict</key>
    <dict>
        <key>PythonExecutable</key>
        <string>@executable_path/../Frameworks/Python.framework/Versions/2.7/Python</string>
        <key>PythonLongVersion</key>
        <string>2.7.3 (default, Mar 19 2013, 18:26:22) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.27)]</string>
        <key>PythonShortVersion</key>
        <string>2.7</string>
        <key>py2app</key>
        <dict>
            <key>alias</key>
            <false/>
            <key>template</key>
            <string>app</string>
            <key>version</key>
            <string>0.7.3</string>
        </dict>
    </dict>
</dict>
</plist>

1 回答

  • 0

    使用py2app的0.7分支的尖端(很快将是0.7.4)我可以部分地重现该问题,因为locale.getlocale()返回(None,None),无论在环境中设置了哪些LC_ *变量 .

    当我在调用locale.getlocale()之前调用locale.setlocale(locale.LC_AL,“”)时,我会获得由LC_ALL或LANG环境变量指示的语言环境信息(当双重时,通过Info.plist中的LSEnvironment键设置)点击应用程序) .

相关问题