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-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);
59 if (bindtextdomain(NAMELOCALIZATIONDOMAIN,pathLocales)==NULL || !isdir(pathLocales))
61 /* source tree and classic build */
62 previousPathLocales = strdup(pathLocales);
63 if (pathLocales) {FREE(pathLocales); pathLocales = NULL;}
65 pathLocales=(char *)MALLOC(sizeof(char)*(strlen(SCIpath)+strlen("/..")+strlen(PATHLOCALIZATIONFILE)+1));
66 strcpy(pathLocales, SCIpath);
67 strcat(pathLocales, "/..");
68 strcat(pathLocales, PATHLOCALIZATIONFILE);
69 if (bindtextdomain(NAMELOCALIZATIONDOMAIN,pathLocales)==NULL || !isdir(pathLocales))
71 /* when it is installed on the system for example /usr/share/locale/ */
72 fprintf(stderr, "Warning: Localization issue: Error while binding the domain from %s or %s: Switch to the default language (English).\n", pathLocales, previousPathLocales);
73 if (previousPathLocales) {FREE(previousPathLocales); previousPathLocales = NULL;}
74 if (pathLocales) {FREE(pathLocales); pathLocales = NULL;}
75 if (SCIpath) {FREE(SCIpath); SCIpath = NULL;}
78 if (previousPathLocales) {FREE(previousPathLocales); previousPathLocales = NULL;}
79 if (pathLocales) {FREE(pathLocales); pathLocales = NULL;}
80 if (SCIpath) {FREE(SCIpath); SCIpath = NULL;}
84 /* set domain for future gettext() calls */
85 ret=textdomain(NAMELOCALIZATIONDOMAIN);
88 fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
91 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN,"UTF-8"); /*such that gettext and dgettext return UTF8 string*/
93 /* Here, the "" means that we will try to use the language of the system
94 * first. If it doesn't work, we switch back to default (English) */
97 /* We look if registry value LANGUAGE exists */
98 /* If not exists the "" means that we will try to use the language of the system.*/
100 char *loadLanguage = getLanguagePreferences();
101 setlanguage(loadLanguage);
102 if (loadLanguage) {FREE(loadLanguage); loadLanguage = NULL;}
106 if (previousPathLocales) FREE(previousPathLocales);
107 if (pathLocales) FREE(pathLocales);
108 if (SCIpath) FREE(SCIpath);
112 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");
116 /*--------------------------------------------------------------------------*/