* Function getlanguage & setlanguage replugged
Sylvestre Ledru [Thu, 18 Oct 2007 12:51:17 +0000 (12:51 +0000)]
* function gettext rewrote
* bug fixed

scilab/modules/localization/Makefile.am
scilab/modules/localization/Makefile.in
scilab/modules/localization/includes/gw_localization.h
scilab/modules/localization/sci_gateway/c/gw_localization.c
scilab/modules/localization/sci_gateway/c/sci_gettext.c
scilab/modules/localization/sci_gateway/localization_gateway.xml
scilab/modules/localization/src/c/InitializeLocalization.c

index 687987d..3f08469 100644 (file)
@@ -15,14 +15,14 @@ endif
 
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_localization.c \
+sci_gateway/c/sci_gettext.c \
 sci_gateway/c/sci_setlanguage.c \
 sci_gateway/c/sci_getlanguage.c
 
 #sci_gateway/c/sci_getlanguagealias.c \
 #sci_gateway/c/sci_getlanguagestable.c \
 #sci_gateway/c/sci_addtext.c \
-#sci_gateway/c/sci_removetext.c \
-#sci_gateway/c/sci_gettext.c
+#sci_gateway/c/sci_removetext.c
 
 libscilocalization_la_CFLAGS=  $(JAVA_JNI_INCLUDE) -Iincludes/ -Isrc/c/ -I$(top_srcdir)/libs/MALLOC/includes/ 
 
index 3ca7771..8286d44 100644 (file)
@@ -91,6 +91,7 @@ am__objects_1 = libscilocalization_la-InitializeLocalization.lo \
        libscilocalization_la-setgetlanguage.lo \
        libscilocalization_la-loadsavelanguage.lo
 am__objects_2 = libscilocalization_la-gw_localization.lo \
+       libscilocalization_la-sci_gettext.lo \
        libscilocalization_la-sci_setlanguage.lo \
        libscilocalization_la-sci_getlanguage.lo
 am_libscilocalization_la_OBJECTS = $(am__objects_1) $(am__objects_2)
@@ -291,6 +292,7 @@ src/c/loadsavelanguage.c
 
 #LOCALIZATION_C_SOURCES += src/c/org_scilab_modules_localization_QueryString.c
 GATEWAY_C_SOURCES = sci_gateway/c/gw_localization.c \
+sci_gateway/c/sci_gettext.c \
 sci_gateway/c/sci_setlanguage.c \
 sci_gateway/c/sci_getlanguage.c
 
@@ -298,8 +300,7 @@ sci_gateway/c/sci_getlanguage.c
 #sci_gateway/c/sci_getlanguagealias.c \
 #sci_gateway/c/sci_getlanguagestable.c \
 #sci_gateway/c/sci_addtext.c \
-#sci_gateway/c/sci_removetext.c \
-#sci_gateway/c/sci_gettext.c
+#sci_gateway/c/sci_removetext.c
 libscilocalization_la_CFLAGS = $(JAVA_JNI_INCLUDE) -Iincludes/ -Isrc/c/ -I$(top_srcdir)/libs/MALLOC/includes/ 
 libscilocalization_la_LDFLAGS = $(JAVA_JNI_LIBS) 
 pkglib_LTLIBRARIES = libscilocalization.la
@@ -449,6 +450,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-gw_localization.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-loadsavelanguage.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-sci_getlanguage.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-sci_gettext.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-sci_setlanguage.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-setgetlanguage.Plo@am__quote@
 
@@ -501,6 +503,13 @@ libscilocalization_la-gw_localization.lo: sci_gateway/c/gw_localization.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscilocalization_la_CFLAGS) $(CFLAGS) -c -o libscilocalization_la-gw_localization.lo `test -f 'sci_gateway/c/gw_localization.c' || echo '$(srcdir)/'`sci_gateway/c/gw_localization.c
 
+libscilocalization_la-sci_gettext.lo: sci_gateway/c/sci_gettext.c
+@am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscilocalization_la_CFLAGS) $(CFLAGS) -MT libscilocalization_la-sci_gettext.lo -MD -MP -MF $(DEPDIR)/libscilocalization_la-sci_gettext.Tpo -c -o libscilocalization_la-sci_gettext.lo `test -f 'sci_gateway/c/sci_gettext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_gettext.c
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/libscilocalization_la-sci_gettext.Tpo $(DEPDIR)/libscilocalization_la-sci_gettext.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_gettext.c' object='libscilocalization_la-sci_gettext.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscilocalization_la_CFLAGS) $(CFLAGS) -c -o libscilocalization_la-sci_gettext.lo `test -f 'sci_gateway/c/sci_gettext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_gettext.c
+
 libscilocalization_la-sci_setlanguage.lo: sci_gateway/c/sci_setlanguage.c
 @am__fastdepCC_TRUE@   $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscilocalization_la_CFLAGS) $(CFLAGS) -MT libscilocalization_la-sci_setlanguage.lo -MD -MP -MF $(DEPDIR)/libscilocalization_la-sci_setlanguage.Tpo -c -o libscilocalization_la-sci_setlanguage.lo `test -f 'sci_gateway/c/sci_setlanguage.c' || echo '$(srcdir)/'`sci_gateway/c/sci_setlanguage.c
 @am__fastdepCC_TRUE@   mv -f $(DEPDIR)/libscilocalization_la-sci_setlanguage.Tpo $(DEPDIR)/libscilocalization_la-sci_setlanguage.Plo
index 27d923a..8700d0e 100644 (file)
@@ -10,11 +10,12 @@ int C2F(gw_localization)(void);
 /*-----------------------------------------------------------------------------------*/ 
 /* interface for the previous function Table */ 
 /*-----------------------------------------------------------------------------------*/ 
-/*int C2F(sci_setlanguage) _PARAMS((char *fname,unsigned long fname_len));
+int C2F(sci_setlanguage) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_getlanguage) _PARAMS((char *fname,unsigned long fname_len));
-int C2F(sci_getlanguagealias) _PARAMS((char *fname,unsigned long fname_len));
-int C2F(sci_getlanguagestable) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_gettext) _PARAMS((char *fname,unsigned long fname_len));
+/*int C2F(sci_getlanguagealias) _PARAMS((char *fname,unsigned long fname_len));
+int C2F(sci_getlanguagestable) _PARAMS((char *fname,unsigned long fname_len));
+
 int C2F(sci_addtext) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_removetext) _PARAMS((char *fname,unsigned long fname_len));*/
 /*-----------------------------------------------------------------------------------*/ 
index 08efdf5..a332960 100644 (file)
@@ -9,14 +9,13 @@
 /*-----------------------------------------------------------------------------------*/ 
 static gw_generic_table Tab[]=
 {
-NULL
-};
-
-/*             {C2F(sci_setlanguage),"setlanguage"},
+               {C2F(sci_setlanguage),"setlanguage"},
                {C2F(sci_getlanguage),"getlanguage"},
-       {C2F(sci_getlanguagealias),"getlanguagealias"},
+               {C2F(sci_gettext),"gettext"}
+};
+                       /*      {C2F(sci_getlanguagealias),"getlanguagealias"},
        {C2F(sci_getlanguagestable),"getlanguagestable"},
-       {C2F(sci_gettext),"gettext"},
+
        {C2F(sci_addtext),"addtext"},
        {C2F(sci_removetext),"removetext"}
 */
index 2eec919..ab19528 100644 (file)
+/**
+ * INRIA 2007 
+ * @author Allan CORNET - initial
+ * @author Sylvestre Ledru <sylvestre.ledru@inria.fr> - Rewrite using gettext
+
 /*-----------------------------------------------------------------------------------*/
-/* INRIA 2007 */
-/* Allan CORNET */
-/*-----------------------------------------------------------------------------------*/
+#include "MALLOC.h"
 #include "machine.h"
 #include "stack-c.h"
 #include "localization.h"
 #include "gw_localization.h"
-#include "QueryStringError.h"
-#include "QueryStringMenu.h"
-#include "QueryStringMessage.h"
-#include "hashtable.h"
-#include "getentrieshashtable.h"
 #include "error_scilab.h"
 /*-----------------------------------------------------------------------------------*/
-static int OneRhs_gettext(void);
-static int TwoRhs_gettext(void);
-static BOOL FreeElmsArray(char **ElemsArray,int nbrElems);
-/*-----------------------------------------------------------------------------------*/
 int C2F(sci_gettext) _PARAMS((char *fname,unsigned long fname_len))
 {
-       CheckRhs(1,2);
-       CheckLhs(1,3);
-
-       if (Rhs == 1)
-       {
-               OneRhs_gettext();
-       }
-       else /* Rhs == 2 */
-       {
-               TwoRhs_gettext();
-       }
-       return 0;
-}
-/*-----------------------------------------------------------------------------------*/
-static int TwoRhs_gettext(void)
-{
-       if ( (Lhs == 2) || (Lhs == 3) )
-       {
-               error_scilab(78,"%s : wrong number of lhs arguments","gettext");
-               return 0;
-       }
-
-       if ( (GetType(1) == sci_strings) && (GetType(2) == sci_strings) )
-       {
-               static int l1,n1,m1;
-
-               char *param1=NULL;
-               char *param2=NULL;
-
-               GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-               param1=cstk(l1);
-
-               GetRhsVar(2,STRING_DATATYPE,&m1,&n1,&l1);
-               param2=cstk(l1);
-
-               if ((strcmp(param1,"errors")==0) || (strcmp(param1,"messages")==0) || (strcmp(param1,"menus")==0))
-               {
-                       char *TranslatedString=NULL;
-
-                       if (strcmp(param1,"errors")==0)
-                       {
-                               TranslatedString=QueryStringError(param2);              
-                       }
-                       else
-                       if (strcmp(param1,"messages")==0)
-                       {
-                               TranslatedString=QueryStringMessage(param2);    
-                       }
-                       else /* menus */
-                       {
-                               TranslatedString=QueryStringMenu(param2);       
-                       }
-
-                       if (TranslatedString)
-                       {
-                               n1=1;
-                               CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(TranslatedString), &m1),&n1,&TranslatedString);
-                               LhsVar(1)=Rhs+1;
-                               C2F(putlhsvar)();       
-                               if (TranslatedString) {FREE(TranslatedString);TranslatedString=NULL;}
-                       }
-                       else
-                       {
-                               m1=0;
-                               n1=0;
-                               l1=0;
-                               CreateVar(Rhs+1,MATRIX_OF_DOUBLE_DATATYPE,  &m1, &n1, &l1);
-                               LhsVar(1)=Rhs+1;
-                               C2F(putlhsvar)();
-                       }
-               }
-               else
-               {
-                       Scierror(999,"invalid first parameter. See help gettext.\n");
-                       return 0;
-               }
-       }
-       else
-       {
-               Scierror(999,"invalid parameter(s).\n");
-               return 0;
-       }
-       return 0;
-}
-/*-----------------------------------------------------------------------------------*/
-static int OneRhs_gettext(void)
-{
-       if (GetType(1) == sci_strings)
-       {
-               static int l1,n1,m1;
-               char *param1=NULL;
-
-               GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-               param1=cstk(l1);
+       CheckRhs(1,1);
+       CheckLhs(1,1);
 
-               if ((strcmp(param1,"errors")==0) || (strcmp(param1,"messages")==0) || (strcmp(param1,"menus")==0))
+       if ( (GetType(1) == sci_strings) )
                {
-                       struct hashtable *Table=NULL;
-
-                       if (strcmp(param1,"errors")==0)
-                       {
-                               Table=GetHashTableScilabErrors();       
-                       }
-                       else
-                       if (strcmp(param1,"messages")==0)
-                       {
-                               Table=GetHashTableScilabMessages();     
-                       }
-                       else /* menus */
-                       {
-                               Table=GetHashTableScilabMenus();        
-                       }
-
-                       if (Table)
-                       {
-                               int numberselemTAGS=0;
-                               int numberselemSTRINGS=0;
-                               int numberselemPATHS=0;
-
-                               char **Tags=NULL;
-                               char **Strings=NULL;
-                               char **Paths=NULL;
-
-                               int n=0;
-                               int m=0;
-
-                               Tags=getTAGSinhashtable(Table,&numberselemTAGS);
-                               Strings=getSTRINGSinhashtable(Table,&numberselemSTRINGS);
-                               Paths=getPATHSinhashtable(Table,&numberselemPATHS);
-
-                               if ( (numberselemSTRINGS != numberselemTAGS) && (numberselemTAGS!= numberselemPATHS) )
-                               {
-                                       Scierror(999,"Problem(s) with hashtable (1).\n");
-                                       return 0;
-                               }
-                               else
-                               {
-                                       
-                                       m=numberselemTAGS;
-                                       n=1;
-
-                                       CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &m, &n,Tags);
-                                       LhsVar(1) = Rhs+1;
-
-                                       if (Lhs >= 2)
-                                       {
-                                               m=numberselemSTRINGS;
-                                               n=1;
-
-                                               CreateVarFromPtr(Rhs+2,MATRIX_OF_STRING_DATATYPE, &m, &n, Strings);
-                                               LhsVar(2) = Rhs+2;
-                                       }
+                       static int l1,n1,m1;
 
-                                       if (Lhs == 3)
-                                       {
-                                               m=numberselemPATHS;
-                                               n=1;
-
-                                               CreateVarFromPtr(Rhs+3,MATRIX_OF_STRING_DATATYPE, &m, &n, Paths);
-                                               LhsVar(3) = Rhs+3;
-                                       }
+                       char *param1=NULL;
+                       char *TranslatedString=NULL;
 
-                                       C2F(putlhsvar)();
-                               }
+                       GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
+                       param1=cstk(l1);
 
-                               FreeElmsArray(Tags,numberselemTAGS);
-                               FreeElmsArray(Strings,numberselemSTRINGS);
-                               FreeElmsArray(Paths,numberselemPATHS);
+                       /* We always have something from this functions because gettext
+                        * is returning the same string if it cannot find it */
+                       TranslatedString=gettext(param1); 
 
-                       }
-                       else
-                       {
-                               Scierror(999,"Problem(s) with hashtable (2).\n");
-                               return 0;
-                       }
-               }
-               else
-               {
-                       Scierror(999,"invalid parameter. See help gettext.\n");
+                       n1=1;
+                       CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(TranslatedString), &m1),&n1,&TranslatedString);
+                       LhsVar(1)=Rhs+1;
+                       C2F(putlhsvar)();       
                        return 0;
                }
-       }
        else
-       {
-               Scierror(999,"invalid first parameter. See help gettext.\n");
-               return 0;
-       }
-               
-       return 0;
-}
-/*-----------------------------------------------------------------------------------*/
-static BOOL FreeElmsArray(char **ElemsArray,int nbrElems)
-{
-       BOOL bOK=FALSE;
-
-       if (ElemsArray)
-       {
-               int i=0;
-               for (i=0;i<nbrElems;i++)
                {
-                       if (ElemsArray[i])
-                       {
-                               FREE(ElemsArray[i]);
-                               ElemsArray[i]=NULL;
-                       }
+                       Scierror(999,"invalid first parameter. See help gettext.\n");
+                       return 0;
                }
-               FREE(ElemsArray);
-               ElemsArray=NULL;
-               bOK=TRUE;
-       }
-
-       return bOK;
 }
 /*-----------------------------------------------------------------------------------*/
index af1d3b8..d57e35a 100644 (file)
 <!-- =================== -->
 
 <PRIMITIVE gatewayId="50" primitiveId="1" primitiveName="setlanguage" />
-<!--
 <PRIMITIVE gatewayId="50" primitiveId="2" primitiveName="getlanguage" />
-<PRIMITIVE gatewayId="50" primitiveId="3" primitiveName="getlanguagealias" />
+<PRIMITIVE gatewayId="50" primitiveId="3" primitiveName="gettext" />
+
+<!--<PRIMITIVE gatewayId="50" primitiveId="3" primitiveName="getlanguagealias" />
 <PRIMITIVE gatewayId="50" primitiveId="4" primitiveName="getlanguagestable" />
-<PRIMITIVE gatewayId="50" primitiveId="5" primitiveName="gettext" />
 <PRIMITIVE gatewayId="50" primitiveId="6" primitiveName="addtext" />
 <PRIMITIVE gatewayId="50" primitiveId="7" primitiveName="removetext" />-->
 </GATEWAY>
\ No newline at end of file
index b649f79..12b7d37 100644 (file)
@@ -45,19 +45,24 @@ BOOL InitializeLocalization(void)
        char *SCIpath=getSCIpath();
        char *pathLocales=NULL;
        char *ret=NULL;
-       pathLocales=(char *)MALLOC(sizeof(char)*(strlen(SCIpath)+strlen(PATHLOCALIZATIONFILE)+1));
        ret=setlocale(LC_ALL,"");
        if (ret==NULL){
                fprintf(stderr, "I18N: Doesn't support your locale.\n" );
                return FALSE;
        }
+
        putEnvLC_ALL(ret);
-       
+       setlanguage(ret);
+
+       pathLocales=(char *)MALLOC(sizeof(char)*(strlen(SCIpath)+strlen(PATHLOCALIZATIONFILE)+1));
+       strcat(pathLocales, SCIpath);
        strcat(pathLocales, PATHLOCALIZATIONFILE);
 
        if (bindtextdomain(NAMELOCALIZATIONDOMAIN,pathLocales)==NULL){
                fprintf(stderr, "Error while binding the domain\n");
                return FALSE;
+       }else{
+               fprintf(stderr, "Domainfile : %s",pathLocales);
        }
 
        if (textdomain(NAMELOCALIZATIONDOMAIN)==NULL){