1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-06-14 18:31:03 +02:00

[W32] Make use of the LANGUAGE envvar.

This commit is contained in:
Werner Koch 2007-02-26 14:26:32 +00:00
parent 6b086c1fe3
commit 958c2a6f69
3 changed files with 139 additions and 70 deletions

5
NEWS
View File

@ -1,6 +1,11 @@
Noteworthy changes in version 1.4.7 Noteworthy changes in version 1.4.7
------------------------------------------------ ------------------------------------------------
* [W32] The environment variable LANGUAGE may be used to override
the language given by HKCU\Software\GNU\GnuPG:Lang. The
language files "*.mo" are expected in a directory named
"gnupg.nls" below the directory with the gpg.exe binary.
Noteworthy changes in version 1.4.6 (2006-12-06) Noteworthy changes in version 1.4.6 (2006-12-06)
------------------------------------------------ ------------------------------------------------

View File

@ -1,3 +1,8 @@
2007-02-26 Werner Koch <wk@g10code.com>
* simple-gettext.c (set_gettext_file): Make use of the envvar
LANGUAGE to allow overriding of the registry setting.
2007-02-12 Werner Koch <wk@g10code.com> 2007-02-12 Werner Koch <wk@g10code.com>
* secmem.c (ptr_into_pool_p): New. * secmem.c (ptr_into_pool_p): New.

View File

@ -43,6 +43,7 @@
#include "types.h" #include "types.h"
#include "util.h" #include "util.h"
#include "windows.h" /* For GetModuleFileName. */
/* The magic number of the GNU message catalog format. */ /* The magic number of the GNU message catalog format. */
#define MAGIC 0x950412de #define MAGIC 0x950412de
@ -232,33 +233,75 @@ load_domain( const char *filename )
} }
/**************** /* Set the file used for translations. Pass a NULL to disable
* Set the file used for translations. Pass a NULL to disable translation. A new filename may be set at anytime. WARNING: After
* translation. A new filename may be set at anytime. If REGKEY is changing the filename you should not access any data retrieved by
* not NULL, the function tries to selected the language the registry gettext().
* key "Lang" below that key. WARNING: After changing the filename you
* should not access any data retrieved by gettext(). If REGKEY is not NULL, the function tries to selected the language
the registry key "Lang" below that key. If in addition the
environment variable LANGUAGE has been set, that value will
override a value set by the registry key.
*/ */
int int
set_gettext_file ( const char *filename, const char *regkey ) set_gettext_file ( const char *filename, const char *regkey )
{ {
struct loaded_domain *domain = NULL; struct loaded_domain *domain = NULL;
if( filename && *filename ) { if ( filename && *filename )
{
if ( filename[0] == '/' if ( filename[0] == '/'
#ifdef HAVE_DRIVE_LETTERS #ifdef HAVE_DRIVE_LETTERS
|| ( isalpha(filename[0]) || ( isalpha(filename[0])
&& filename[1] == ':' && filename[1] == ':'
&& (filename[2] == '/' || filename[2] == '\\') ) && (filename[2] == '/' || filename[2] == '\\') )
#endif #endif
) { )
{
/* absolute path - use it as is */ /* absolute path - use it as is */
domain = load_domain( filename ); domain = load_domain( filename );
} }
else if (regkey) { /* Standard. */ else if (regkey) /* Standard. */
{
char *instdir, *langid, *fname; char *instdir, *langid, *fname;
char *p; char *p;
int envvar_mode = 0;
again:
if (!envvar_mode && (p = getenv ("LANGUAGE")) && *p)
{
envvar_mode = 1;
langid = malloc (strlen (p)+1);
if (!langid)
return -1;
strcpy (langid, p);
/* We only make use of the first language given. Strip
the rest. */
p = strchr (langid, ':');
if (p)
*p = 0;
/* In the $LANGUAGE case we do not use the registered
installation directory but the one where the gpg
binary has been found. */
instdir = malloc (MAX_PATH+5);
if ( !instdir || !GetModuleFileName (NULL, instdir, MAX_PATH) )
{
free (langid);
free (instdir);
return -1; /* Error getting the process' file name. */
}
p = strrchr (instdir, DIRSEP_C);
if (!p)
{
free (langid);
free (instdir);
return -1; /* Invalid file name returned. */
}
*p = 0;
}
else
{
instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE",
regkey, regkey,
"Install Directory"); "Install Directory");
@ -267,24 +310,27 @@ set_gettext_file ( const char *filename, const char *regkey )
langid = read_w32_registry_string (NULL, /* HKCU then HKLM */ langid = read_w32_registry_string (NULL, /* HKCU then HKLM */
regkey, regkey,
"Lang"); "Lang");
if (!langid) { if (!langid)
{
free (instdir); free (instdir);
return -1; return -1;
} }
}
/* Strip stuff after a dot in case the user tried to enter /* Strip stuff after a dot in case the user tried to enter
* the entire locale synatcs as usual for POSIX. */ the entire locale syntacs as usual for POSIX. */
p = strchr (langid, '.'); p = strchr (langid, '.');
if (p) if (p)
*p = 0; *p = 0;
/* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We /* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We
use a directory below the installation directory with use a directory below the installation directory with the
the domain included in case the software has been domain included in case the software has been insalled
insalled with other software altogether at the same with other software altogether at the same place. */
place. */
fname = malloc (strlen (instdir) + 1 + strlen (filename) + 5 fname = malloc (strlen (instdir) + 1 + strlen (filename) + 5
+ strlen (langid) + 3 + 1); + strlen (langid) + 3 + 1);
if (!fname) { if (!fname)
{
free (instdir); free (instdir);
free (langid); free (langid);
return -1; return -1;
@ -294,26 +340,39 @@ set_gettext_file ( const char *filename, const char *regkey )
free (instdir); free (instdir);
free (langid); free (langid);
/* Better make sure that we don't mix forward and /* Better make sure that we don't mix forward and backward
backward slashes. It seems that some Windoze slashes. It seems that some Windoze versions don't
versions don't accept this. */ accept this. */
for (p=fname; *p; p++) { for (p=fname; *p; p++)
{
if (*p == '/') if (*p == '/')
*p = '\\'; *p = '\\';
} }
domain = load_domain (fname); domain = load_domain (fname);
free(fname); free(fname);
if (!domain && envvar_mode == 1)
{
/* In case it failed, we try again using the registry
method. */
envvar_mode++;
goto again;
} }
}
if (!domain) if (!domain)
return -1; return -1;
} }
if( the_domain ) { if ( the_domain )
{
struct overflow_space_s *os, *os2; struct overflow_space_s *os, *os2;
free ( the_domain->data ); free ( the_domain->data );
free ( the_domain->mapped ); free ( the_domain->mapped );
for (os=the_domain->overflow_space; os; os = os2) { for (os=the_domain->overflow_space; os; os = os2)
{
os2 = os->next; os2 = os->next;
free (os); free (os);
} }