Unless files
[scilab.git] / scilab / modules / localization / sci_gateway / c / sci_setlanguage.c
1 /*--------------------------------------------------------------------------*/
2 /* INRIA 2007/2008 */
3 /* @author Allan CORNET */
4 /* @author Sylvestre LEDRU */
5
6 /*--------------------------------------------------------------------------*/
7 #include "gw_localization.h"
8 #include "setgetlanguage.h"
9 #include "Scierror.h"
10 #include "sciprint.h"
11 #include "warningmode.h"
12 #include "defaultlanguage.h"
13 #include "MALLOC.h"
14 #include "loadhashtableslocalization.h"
15 #include "localization.h"
16 #include "stack-c.h"
17 /*--------------------------------------------------------------------------*/
18 int C2F(sci_setlanguage) _PARAMS((char *fname,unsigned long fname_len))
19 {
20         static int l1,n1,m1;
21
22         CheckRhs(0,1);
23         CheckLhs(1,1);
24
25         if (GetType(1) == sci_strings)
26         {
27                 char *param=NULL;
28                 char *newlanguage=NULL;
29
30                 GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
31                 param=cstk(l1);
32                 /* Convert small code to long code fr => fr_FR */
33                 newlanguage=convertlanguagealias(param);
34
35                 if ( LanguageIsOK(param) && (newlanguage == NULL) )
36                 {
37                   newlanguage=param;
38                 }
39
40                 if (newlanguage)
41                 {
42                         if (needtochangelanguage(newlanguage))
43                         {
44                                 if (!setlanguage(newlanguage,TRUE,TRUE))
45                                 {
46                                         CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
47                                         *istk(l1)=(int)(FALSE);
48                                 }
49                                 else
50                                 {
51                                         CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
52                                         *istk(l1)=(int)(TRUE);
53                                 }
54                         }
55                         else
56                         {
57                                 /* do nothing */
58                                 CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
59                                 *istk(l1)=(int)(TRUE);
60                         }
61                 }
62                 else
63                 {
64                         if (getWarningMode())
65                         {
66                                 sciprint(_("Unsupported language '%s'.\n"),param);
67                                 sciprint(_("Switching to default language : '%s'.\n"),SCILABDEFAULTLANGUAGE);   
68                         }
69                         setlanguage(SCILABDEFAULTLANGUAGE,TRUE,TRUE);
70
71                         CreateVar(Rhs+1,MATRIX_OF_BOOLEAN_DATATYPE, &n1,&n1,&l1);
72                         *istk(l1)=(int)(FALSE);
73                 }
74                 LhsVar(1)=Rhs+1;
75                 C2F(putlhsvar)();
76         }
77         else
78         {
79                 Scierror(999,_("%s: Wrong type for first input argument: String expected.\n"),fname);
80                 return 0;
81         }
82
83         return 0;
84 }
85 /*--------------------------------------------------------------------------*/