[Spice-devel] [spice-gtk 3/3] win32: Convert locale dir from UTF-8 to local encoding

Frediano Ziglio fziglio at redhat.com
Thu May 3 11:28:27 UTC 2018


> 
> As indicated in gtk+ win32 gtk_get_localedir [1], bindtextdomain() is not
> UTF-8 aware on win32, so it needs a filename in locale encoding
> 

Stupid questions: what happens if the directory name has like Chines/Japanese
characters and current locale is latin 1 kind of (like western European) ?
Maybe would be better to attempt to use short names if possible (in Windows
a file can have 2 names, one long and one short, usually the short is less
of a problem as DOS compatible).

I suppose from the code g_win32_get_package_installation_directory_of_module
returns utf-8 encoded path.

> [1] https://gitlab.gnome.org/GNOME/gtk/blob/master/gtk/gtkwin32.c#L187
> ---
>  src/spice-glib-main.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/src/spice-glib-main.c b/src/spice-glib-main.c
> index c2bd7ca6..881015fc 100644
> --- a/src/spice-glib-main.c
> +++ b/src/spice-glib-main.c
> @@ -32,9 +32,13 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason,
> LPVOID lpvReserved)
>      if (fdwReason == DLL_PROCESS_ATTACH) {
>          char *basedir =
>              g_win32_get_package_installation_directory_of_module(hinstDLL);
> -        char *localedir = g_build_filename(basedir, "share", "locale",
> NULL);
> +        char *utf8_localedir = g_build_filename(basedir, "share", "locale",
> NULL);
> +        /* bindtextdomain's 2nd argument is not UTF-8 aware */
> +        char *localedir = g_win32_locale_filename_from_utf8
> (utf8_localedir);
> +
>          bindtextdomain(GETTEXT_PACKAGE, localedir);
>          g_free(localedir);
> +        g_free(utf8_localedir);
>          g_free(basedir);
>          bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
>      }

Frediano


More information about the Spice-devel mailing list