2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008 - INRIA - Sylvestre LEDRU
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
22 #error "Cannot find locale.h despite that libintl.h is available"
31 #include "InitializeLocalization.h"
32 #include "localization.h"
33 #include "setgetSCIpath.h"
35 #include "scilabDefaults.h"
36 #include "setgetlanguage.h"
39 #include "strdup_windows.h"
40 #include "LanguagePreferences_Windows.h"
43 /*--------------------------------------------------------------------------*/
45 BOOL InitializeLocalization(void)
49 char *SCIpath = getSCIpath();
50 char *pathLocales = NULL, *previousPathLocales = NULL;
53 /* set directory containing message catalogs */
54 pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen(PATHLOCALIZATIONFILE) + 1));
56 strcpy(pathLocales, SCIpath);
57 strcat(pathLocales, PATHLOCALIZATIONFILE);
58 if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
60 /* source tree and classic build */
61 previousPathLocales = strdup(pathLocales);
68 pathLocales = (char *)MALLOC(sizeof(char) * (strlen(SCIpath) + strlen("/..") + strlen(PATHLOCALIZATIONFILE) + 1));
69 strcpy(pathLocales, SCIpath);
70 strcat(pathLocales, "/..");
71 strcat(pathLocales, PATHLOCALIZATIONFILE);
72 if (bindtextdomain(NAMELOCALIZATIONDOMAIN, pathLocales) == NULL || !isdir(pathLocales))
74 /* when it is installed on the system for example /usr/share/locale/ */
75 fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);
77 // Set default behaviour
78 textdomain(NAMELOCALIZATIONDOMAIN);
79 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
83 /* We look if registry value LANGUAGE exists */
84 /* If not exists the "" means that we will try to use the language of the system.*/
86 char *loadLanguage = getLanguagePreferences();
87 setlanguage(loadLanguage);
96 if (previousPathLocales)
98 FREE(previousPathLocales);
99 previousPathLocales = NULL;
113 if (previousPathLocales)
115 FREE(previousPathLocales);
116 previousPathLocales = NULL;
131 /* set domain for future gettext() calls */
132 ret = textdomain(NAMELOCALIZATIONDOMAIN);
135 fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
139 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); /*such that gettext and dgettext return UTF8 string*/
141 /* Here, the "" means that we will try to use the language of the system
142 * first. If it doesn't work, we switch back to default (English) */
145 /* We look if registry value LANGUAGE exists */
146 /* If not exists the "" means that we will try to use the language of the system.*/
148 char *loadLanguage = getLanguagePreferences();
149 setlanguage(loadLanguage);
158 if (previousPathLocales)
160 FREE(previousPathLocales);
173 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");
177 /*--------------------------------------------------------------------------*/