2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre LEDRU
4 * Copyright (C) 2011 - 2011 - DIGITEO - Bruno JOFRET
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
26 #error "Cannot find locale.h despite that libintl.h is available"
34 #include "sci_malloc.h"
35 #include "InitializeLocalization.h"
36 #include "localization.h"
38 #include "scilabDefaults.h"
39 #include "setgetlanguage.h"
41 #include "os_string.h"
43 #include "LanguagePreferences_Windows.h"
46 //#define FORCE_LOCALE_EN_US
47 /*--------------------------------------------------------------------------*/
49 BOOL InitializeLocalization(void)
53 char *SCIpath = getSCI();
54 char *pathLocales = NULL;
55 char *previousPathLocales = NULL;
58 /* set directory containing message catalogs */
59 pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen(PATHLOCALIZATIONFILE) + 1));
61 strcpy(pathLocales, SCIpath);
62 strcat(pathLocales, PATHLOCALIZATIONFILE);
63 if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
65 /* source tree and classic build */
66 previousPathLocales = os_strdup(pathLocales);
70 pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen("/..") + strlen(PATHLOCALIZATIONFILE) + 1));
71 strcpy(pathLocales, SCIpath);
72 strcat(pathLocales, "/..");
73 strcat(pathLocales, PATHLOCALIZATIONFILE);
74 if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
76 /* when it is installed on the system for example /usr/share/locale/ */
77 fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);
79 // Set default behaviour
80 textdomain(NAMELOCALIZATIONDOMAIN);
81 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
85 /* We look if registry value LANGUAGE exists */
86 /* If not exists the "" means that we will try to use the language of the system.*/
88 wchar_t* loadLanguage = getLanguagePreferences();
89 setlanguage(loadLanguage);
98 if (previousPathLocales)
100 FREE(previousPathLocales);
101 previousPathLocales = NULL;
109 if (previousPathLocales)
111 FREE(previousPathLocales);
112 previousPathLocales = NULL;
121 /* set domain for future gettext() calls */
122 ret = textdomain(NAMELOCALIZATIONDOMAIN);
125 fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
128 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); /*such that gettext and dgettext return UTF8 string*/
130 /* Here, the "" means that we will try to use the language of the system
131 * first. If it doesn't work, we switch back to default (English) */
132 #ifdef FORCE_LOCALE_EN_US
138 /* We look if registry value LANGUAGE exists */
139 /* If not exists the "" means that we will try to use the language of the system.*/
141 #ifdef FORCE_LOCALE_EN_US
142 setlanguage(L"en_US");
144 wchar_t *loadLanguage = getLanguagePreferences();
145 setlanguage(loadLanguage);
156 fprintf(stderr, "Localization: setlocale didn't exist on the computer used to compile Scilab ! This is abnormal ! No localization will be working for this distribution of Scilab.\n");
160 /*--------------------------------------------------------------------------*/