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,96 +233,154 @@ 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 */ {
domain = load_domain( filename ); /* absolute path - use it as is */
domain = load_domain( filename );
} }
else if (regkey) { /* Standard. */ else if (regkey) /* Standard. */
char *instdir, *langid, *fname; {
char *p; char *instdir, *langid, *fname;
char *p;
int envvar_mode = 0;
instdir = read_w32_registry_string ("HKEY_LOCAL_MACHINE", again:
regkey, if (!envvar_mode && (p = getenv ("LANGUAGE")) && *p)
"Install Directory"); {
if (!instdir) envvar_mode = 1;
langid = malloc (strlen (p)+1);
if (!langid)
return -1; return -1;
langid = read_w32_registry_string (NULL, /* HKCU then HKLM */ strcpy (langid, p);
regkey, /* We only make use of the first language given. Strip
"Lang"); the rest. */
if (!langid) { p = strchr (langid, ':');
free (instdir); if (p)
return -1;
}
/* Strip stuff after a dot in case the user tried to enter
* the entire locale synatcs as usual for POSIX. */
p = strchr (langid, '.');
if (p)
*p = 0; *p = 0;
/* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We /* In the $LANGUAGE case we do not use the registered
use a directory below the installation directory with installation directory but the one where the gpg
the domain included in case the software has been binary has been found. */
insalled with other software altogether at the same instdir = malloc (MAX_PATH+5);
place. */ if ( !instdir || !GetModuleFileName (NULL, instdir, MAX_PATH) )
fname = malloc (strlen (instdir) + 1 + strlen (filename) + 5 {
+ strlen (langid) + 3 + 1); free (langid);
if (!fname) { free (instdir);
free (instdir); return -1; /* Error getting the process' file name. */
free (langid); }
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",
regkey,
"Install Directory");
if (!instdir)
return -1; return -1;
langid = read_w32_registry_string (NULL, /* HKCU then HKLM */
regkey,
"Lang");
if (!langid)
{
free (instdir);
return -1;
}
} }
strcpy (stpcpy (stpcpy (stpcpy (stpcpy ( stpcpy (fname,
instdir),"\\"), filename), ".nls\\"), langid), ".mo");
free (instdir);
free (langid);
/* Better make sure that we don't mix forward and /* Strip stuff after a dot in case the user tried to enter
backward slashes. It seems that some Windoze the entire locale syntacs as usual for POSIX. */
versions don't accept this. */ p = strchr (langid, '.');
for (p=fname; *p; p++) { if (p)
if (*p == '/') *p = 0;
*p = '\\';
/* Build the key: "<instdir>/<domain>.nls/<langid>.mo" We
use a directory below the installation directory with the
domain included in case the software has been insalled
with other software altogether at the same place. */
fname = malloc (strlen (instdir) + 1 + strlen (filename) + 5
+ strlen (langid) + 3 + 1);
if (!fname)
{
free (instdir);
free (langid);
return -1;
}
strcpy (stpcpy (stpcpy (stpcpy (stpcpy ( stpcpy (fname,
instdir),"\\"), filename), ".nls\\"), langid), ".mo");
free (instdir);
free (langid);
/* Better make sure that we don't mix forward and backward
slashes. It seems that some Windoze versions don't
accept this. */
for (p=fname; *p; p++)
{
if (*p == '/')
*p = '\\';
}
domain = load_domain (fname);
free(fname);
if (!domain && envvar_mode == 1)
{
/* In case it failed, we try again using the registry
method. */
envvar_mode++;
goto again;
} }
domain = load_domain (fname);
free(fname);
} }
if (!domain)
return -1; if (!domain)
return -1;
} }
if( the_domain ) { if ( the_domain )
struct overflow_space_s *os, *os2; {
free( the_domain->data ); struct overflow_space_s *os, *os2;
free( the_domain->mapped );
for (os=the_domain->overflow_space; os; os = os2) { free ( the_domain->data );
os2 = os->next; free ( the_domain->mapped );
free (os); for (os=the_domain->overflow_space; os; os = os2)
{
os2 = os->next;
free (os);
} }
free( the_domain ); free ( the_domain );
the_domain = NULL; the_domain = NULL;
} }
the_domain = domain; the_domain = domain;
return 0; return 0;
} }