Packp3d and system's language

Hello, I need to retrieve the system’s language, but I can’t get it working with packp3d. I’ve this program:

import direct.directbase.DirectStart, locale
print locale.getdefaultlocale()[ 0 ]

Launching it from console (with ppython), it prints correctly it_IT on my machines (these are setted to the italian language, and I tested it on Windows/OSX/Linux).

The problem arises when I need to deploy it. I’ve packed it with packp3d, and I’ve launched the p3d file on the same machines. Only on Windows I get the same behaviour (it prints it_IT). Instead, on OSX and Linux, it prints None.

Where am I wrong? Thanks!

Try using the parameter “-c keep_user_env=1” on the packp3d command line. This tells the runtime environment to preserve the user’s environment variables.


Thank you so much! Now it works on Windows and Linux, but on OSX it doesn’t work again (same behaviour: it prints None). What can I do now? Thanks!

Hmm, really? I will have to investigate to discover what mechanism OSX uses to communicate the system locale to processes.


However, with your hint I have found a solution to my problem: with an instruction like

print os.environ.get( 'LANG' )

I can retrieve the language set, so thank you again!

Sorry, I spoke too soon. With this solution I’ve two problems.

  1. At runtime I need to create several files (savegames, settings, …). With p3d files it works (it creates these files in the runtime’s start directory). But when I create installers from the p3d file with pdeploy it doesn’t work: these files are created in the current (launching) directory, not in the installation one. Instead, without keep_user_env these are created in the start folder in the installation directory (this is a better behaviour for me because I know the position of these files and I can retrieve them). Is it possible to replicate the behaviour of the execution without keep_user_env when keep_user_env is active (that is, create these files in the start folder)?

  2. Consider the following code:

import direct.directbase.DirectStart, os
from direct.gui.OnscreenText import OnscreenText
OnscreenText( text = str( os.environ.get( 'LANG' ) ) )

(a slightly modification of the previous that permits you to see the output without the console) I packed it with packp3d (and keep_user_env). On OSX, if I launch it from console (e.g. panda3d test.p3d) it works (it prints it_IT.UTF-8). But, if I launch it from GUI (double-clicking the test.p3d icon) it prints None! Note that this doesn’t happen on Linux (either from console and GUI it prints the correct value).

So, the workaround doesn’t work, and I’m stuck at these two problems. :frowning: