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);
73 pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen("/..") + strlen(PATHLOCALIZATIONFILE) + 1));
74 strcpy(pathLocales, SCIpath);
75 strcat(pathLocales, "/..");
76 strcat(pathLocales, PATHLOCALIZATIONFILE);
77 if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
79 /* when it is installed on the system for example /usr/share/locale/ */
80 fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);
82 // Set default behaviour
83 textdomain(NAMELOCALIZATIONDOMAIN);
84 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
88 /* We look if registry value LANGUAGE exists */
89 /* If not exists the "" means that we will try to use the language of the system.*/
91 wchar_t* loadLanguage = getLanguagePreferences();
92 setlanguage(loadLanguage);
101 if (previousPathLocales)
103 FREE(previousPathLocales);
104 previousPathLocales = NULL;
118 if (previousPathLocales)
120 FREE(previousPathLocales);
121 previousPathLocales = NULL;
136 /* set domain for future gettext() calls */
137 ret = textdomain(NAMELOCALIZATIONDOMAIN);
140 fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
143 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); /*such that gettext and dgettext return UTF8 string*/
145 /* Here, the "" means that we will try to use the language of the system
146 * first. If it doesn't work, we switch back to default (English) */
147 #ifdef FORCE_LOCALE_EN_US
153 /* We look if registry value LANGUAGE exists */
154 /* If not exists the "" means that we will try to use the language of the system.*/
156 #ifdef FORCE_LOCALE_EN_US
157 setlanguage(L"en_US");
159 wchar_t *loadLanguage = getLanguagePreferences();
160 setlanguage(loadLanguage);
171 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");
175 /*--------------------------------------------------------------------------*/