diff --git a/libvips/include/vips/util.h b/libvips/include/vips/util.h index b5a4f7a6..fb26e5b6 100644 --- a/libvips/include/vips/util.h +++ b/libvips/include/vips/util.h @@ -332,6 +332,7 @@ guint32 vips__random( guint32 seed ); guint32 vips__random_add( guint32 seed, int value ); const char *vips__icc_dir( void ); +const char *vips__locale_dir( void ); #ifdef __cplusplus } diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index a606f8a4..56a0c9c7 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -267,7 +267,6 @@ vips_init( const char *argv0 ) char *prgname; const char *prefix; const char *libdir; - char name[256]; /* Two stage done handling: 'done' means we've completed, 'started' * means we're currently initialising. Use this to prevent recursive @@ -342,10 +341,7 @@ vips_init( const char *argv0 ) /* Get i18n .mo files from $VIPSHOME/share/locale/. */ - vips_snprintf( name, 256, - "%s" G_DIR_SEPARATOR_S "share" G_DIR_SEPARATOR_S "locale", - prefix ); - bindtextdomain( GETTEXT_PACKAGE, name ); + bindtextdomain( GETTEXT_PACKAGE, vips__locale_dir() ); bind_textdomain_codeset( GETTEXT_PACKAGE, "UTF-8" ); /* Deprecated, this is just for compat. diff --git a/libvips/iofuncs/util.c b/libvips/iofuncs/util.c index 8ff1e631..ff33f248 100644 --- a/libvips/iofuncs/util.c +++ b/libvips/iofuncs/util.c @@ -1969,3 +1969,40 @@ vips__icc_dir( void ) (GThreadFunc) vips_icc_dir_once, NULL ) ); } +#ifdef OS_WIN32 +static HMODULE vips_dll = NULL; +#ifdef DLL_EXPORT +BOOL WINAPI +DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) +{ + if( fdwReason == DLL_PROCESS_ATTACH ) + vips_dll = hinstDLL; + + return( TRUE ); +} +#endif +#endif + +static void * +vips_locale_dir_once( void *null ) +{ + char *prefix; + +#ifdef OS_WIN32 + prefix = g_win32_get_package_installation_directory_of_module( + vips_dll ), +#else + prefix = (char *) g_getenv( "VIPSHOME" ); +#endif + + return( (void *) g_build_filename( prefix, "share", "locale", NULL ) ); +} + +const char * +vips__locale_dir( void ) +{ + static GOnce once = G_ONCE_INIT; + + return( (const char *) g_once( &once, + (GThreadFunc) vips_locale_dir_once, NULL ) ); +}