de60c2f8c3a5c8b9553a8f97e6de3eba39684854
[platform/upstream/atk.git] / atk / atkprivate.c
1 /* ATK -  Accessibility Toolkit
2  *
3  * Copyright (C) 2014 Igalia, S.L.
4  *
5  * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "config.h"
24
25 #include <string.h>
26 #include <locale.h>
27
28 #include <glib-object.h>
29 #include <glib/gi18n-lib.h>
30
31 #include "atkprivate.h"
32
33 #ifdef G_OS_WIN32
34
35 static const char *
36 get_atk_locale_dir (void)
37 {
38   static gchar *atk_localedir = NULL;
39
40   if (!atk_localedir)
41     {
42       const gchar *p;
43       gchar *root, *temp;
44       
45       /* ATK_LOCALEDIR might end in either /lib/locale or
46        * /share/locale. Scan for that slash.
47        */
48       p = ATK_LOCALEDIR + strlen (ATK_LOCALEDIR);
49       while (*--p != '/')
50         ;
51       while (*--p != '/')
52         ;
53
54       root = g_win32_get_package_installation_directory_of_module (atk_dll);
55       temp = g_build_filename (root, p, NULL);
56       g_free (root);
57
58       /* atk_localedir is passed to bindtextdomain() which isn't
59        * UTF-8-aware.
60        */
61       atk_localedir = g_win32_locale_filename_from_utf8 (temp);
62       g_free (temp);
63     }
64   return atk_localedir;
65 }
66
67 #undef ATK_LOCALEDIR
68
69 #define ATK_LOCALEDIR get_atk_locale_dir()
70
71 #endif
72
73 void
74 _gettext_initialization (void)
75 {
76 #ifdef ENABLE_NLS
77   static gboolean gettext_initialized = FALSE;
78
79   if (!gettext_initialized)
80     {
81       const char *dir = g_getenv ("ATK_ALT_LOCALEDIR");
82
83       gettext_initialized = TRUE;
84       if (dir == NULL)
85         dir = ATK_LOCALEDIR;
86
87       bindtextdomain (GETTEXT_PACKAGE, dir);
88 #ifdef HAVE_BIND_TEXTDOMAIN_CODESET
89       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
90 #endif
91     }
92 #endif
93 }
94
95 /*
96  * Compacts a name. For example: to get "accelerator label" instead of
97  * "accelerator-label"
98  */
99 void
100 _compact_name (gchar *name)
101 {
102   gchar *p = name;
103
104   while (*p)
105     {
106       if (*p == '-')
107         *p = ' ';
108       p++;
109     }
110 }