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) を返します (
端末の環境設定が正しいため)

ダブルクリックすると、端末から実行したときとは異なる環境でアプリが実行されることがわかったので、アプリのデフォルトのエンコーディング変数を設定しようとしています。

私が見つけた提案を試してみました: Mac OS X の py2app パッケージ化された Python アプリで、シ​​ステムの既定の言語/ロケールを取得するにはどうすればよいですか? http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPInternational/Articles/ChoosingLocalizations.html の指示に従いました。

CFBundleLocalizationsLSEnvironmentキーの両方をアプリ バンドル内の Info.plist (以下に掲載) に追加しましたが、getlocale() 関数は (None,None) を返し続けます

Python がこれらの変数を取得できるように、OS X アプリ用にこれらの変数を正しく設定するように教えてもらえますか?

<?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>
4

1 に答える 1

0

py2app の 0.7 ブランチ (近いうちに 0.7.4 になる予定) のヒントを使用して、問題を部分的に再現できます。環境で設定されている LC_* 変数に関係なく、locale.getlocale() は (None, None) を返します。 .

locale.getlocale() を呼び出す前に locale.setlocale(locale.LC_AL, "") を呼び出すと、LC_ALL または LANG 環境変数 (Info.plist の LSEnvironment キーを介して設定された double-アプリをクリックします)。

于 2013-03-26T15:35:00.297 に答える