* more tests for localization
Sylvestre Ledru [Fri, 4 Jan 2008 17:07:21 +0000 (17:07 +0000)]
* function dgettext added
* better management of setlanguage
* string updated
* better init of localization

17 files changed:
scilab/modules/localization/Makefile.am
scilab/modules/localization/Makefile.in
scilab/modules/localization/help/en_US/dgettext.xml [new file with mode: 0644]
scilab/modules/localization/help/en_US/getdefaultlanguage.xml [new file with mode: 0644]
scilab/modules/localization/help/en_US/gettext.xml
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
scilab/modules/localization/src/c/setgetlanguage.c
scilab/modules/localization/src/c/tableslanguages.h
scilab/modules/localization/tests/unit_tests/dgettext.dia.ref [new file with mode: 0644]
scilab/modules/localization/tests/unit_tests/dgettext.tst [new file with mode: 0644]
scilab/modules/localization/tests/unit_tests/getlanguage.tst
scilab/modules/localization/tests/unit_tests/gettext.dia.ref [new file with mode: 0644]
scilab/modules/localization/tests/unit_tests/gettext.tst [new file with mode: 0644]

index 80ef9e7..8fb492f 100644 (file)
@@ -15,6 +15,7 @@ endif
 
 GATEWAY_C_SOURCES = sci_gateway/c/gw_localization.c \
 sci_gateway/c/sci_gettext.c \
+sci_gateway/c/sci_dgettext.c \
 sci_gateway/c/sci_setlanguage.c \
 sci_gateway/c/sci_getdefaultlanguage.c \
 sci_gateway/c/sci_getlanguage.c
index c46fdde..9f8c973 100644 (file)
@@ -93,6 +93,7 @@ am__objects_1 = libscilocalization_la-InitializeLocalization.lo \
        libscilocalization_la-loadsavelanguage.lo
 am__objects_2 = libscilocalization_la-gw_localization.lo \
        libscilocalization_la-sci_gettext.lo \
+       libscilocalization_la-sci_dgettext.lo \
        libscilocalization_la-sci_setlanguage.lo \
        libscilocalization_la-sci_getdefaultlanguage.lo \
        libscilocalization_la-sci_getlanguage.lo
@@ -304,11 +305,11 @@ src/c/InitializeLocalization.c \
 src/c/setgetlanguage.c \
 src/c/loadsavelanguage.c
 
-#src/c/TerminateLocalization.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_dgettext.c \
 sci_gateway/c/sci_setlanguage.c \
 sci_gateway/c/sci_getdefaultlanguage.c \
 sci_gateway/c/sci_getlanguage.c
@@ -485,6 +486,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-InitializeLocalization.Plo@am__quote@
 @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_dgettext.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscilocalization_la-sci_getdefaultlanguage.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@
@@ -547,6 +549,13 @@ libscilocalization_la-sci_gettext.lo: sci_gateway/c/sci_gettext.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-sci_gettext.lo `test -f 'sci_gateway/c/sci_gettext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_gettext.c
 
+libscilocalization_la-sci_dgettext.lo: sci_gateway/c/sci_dgettext.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_dgettext.lo -MD -MP -MF $(DEPDIR)/libscilocalization_la-sci_dgettext.Tpo -c -o libscilocalization_la-sci_dgettext.lo `test -f 'sci_gateway/c/sci_dgettext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_dgettext.c
+@am__fastdepCC_TRUE@   mv -f $(DEPDIR)/libscilocalization_la-sci_dgettext.Tpo $(DEPDIR)/libscilocalization_la-sci_dgettext.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_dgettext.c' object='libscilocalization_la-sci_dgettext.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_dgettext.lo `test -f 'sci_gateway/c/sci_dgettext.c' || echo '$(srcdir)/'`sci_gateway/c/sci_dgettext.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
diff --git a/scilab/modules/localization/help/en_US/dgettext.xml b/scilab/modules/localization/help/en_US/dgettext.xml
new file mode 100644 (file)
index 0000000..c0065a7
--- /dev/null
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE MAN SYSTEM "../../../../modules/helptools/help.dtd">
+<MAN>
+  <LANGUAGE>eng</LANGUAGE>
+
+  <TITLE>dgettext</TITLE>
+
+  <TYPE>Scilab Function</TYPE>
+
+  <DATE>$LastChangedDate: 2007-11-15 13:33:00 +0200 (thu., 15 nov. 2007)$</DATE>
+
+  <SHORT_DESCRIPTION name="gettext">get text translated into the current locale and a specific domain domain.</SHORT_DESCRIPTION>
+
+  <CALLING_SEQUENCE>
+    <CALLING_SEQUENCE_ITEM>msg=dgettext(domain, myString)</CALLING_SEQUENCE_ITEM>
+
+  </CALLING_SEQUENCE>
+
+  <PARAM>
+    <PARAM_INDENT>
+      <PARAM_ITEM>
+        <PARAM_NAME>domain</PARAM_NAME>
+
+        <PARAM_NAME>string</PARAM_NAME>
+
+        <PARAM_DESCRIPTION>
+          <SP>: The name of the message domain</SP>
+          <SP>: the message to be translated</SP>
+
+        </PARAM_DESCRIPTION>
+      </PARAM_ITEM>
+    </PARAM_INDENT>
+  </PARAM>
+
+  <DESCRIPTION>
+    <P><VERB>dgettext</VERB> get the translation of a string to the current locale in a specified message domain.</P>
+  </DESCRIPTION>
+
+  <EXAMPLE><![CDATA[
+
+dgettext('scilab','Startup execution:')
+  ]]></EXAMPLE>
+  <SEE_ALSO>
+    <SEE_ALSO_ITEM>
+      <LINK>gettext</LINK>
+    </SEE_ALSO_ITEM>
+  </SEE_ALSO>
+  <AUTHORS>
+    <AUTHORS_ITEM>Sylvestre Ledru</AUTHORS_ITEM>
+  </AUTHORS>
+</MAN>
\ No newline at end of file
diff --git a/scilab/modules/localization/help/en_US/getdefaultlanguage.xml b/scilab/modules/localization/help/en_US/getdefaultlanguage.xml
new file mode 100644 (file)
index 0000000..2633922
--- /dev/null
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE MAN SYSTEM "../../../../modules/helptools/help.dtd">
+<MAN>
+  <LANGUAGE>eng</LANGUAGE>
+
+  <TITLE>getdefaultlanguage</TITLE>
+
+  <TYPE>Scilab Function</TYPE>
+
+  <DATE>$LastChangedDate: 2007-04-22 18:33:00 +0200 (dim., 22 avr. 2007) $</DATE>
+  <SHORT_DESCRIPTION name="getlanguage">getdefaultlanguage() returns the default language used by Scilab.</SHORT_DESCRIPTION>
+
+  <CALLING_SEQUENCE>
+    <CALLING_SEQUENCE_ITEM>getdefaultlanguage()</CALLING_SEQUENCE_ITEM>
+  </CALLING_SEQUENCE>
+
+  <DESCRIPTION>
+    <P><VERB>getdefaultlanguage()</VERB> returns the default language used by Scilab.
+By default, this function should return en_US.
+</P>
+  </DESCRIPTION>
+
+    <EXAMPLE>
+<![CDATA[
+getdefaultlanguage()
+ ]]>
+  </EXAMPLE>
+
+  <SEE_ALSO>
+    <SEE_ALSO_ITEM>
+      <LINK>setlanguage</LINK>
+      <LINK>getlanguage</LINK>
+    </SEE_ALSO_ITEM>
+  </SEE_ALSO>
+
+  <AUTHORS>
+    <AUTHORS_ITEM>Sylvestre Ledru</AUTHORS_ITEM>
+  </AUTHORS>
+</MAN>
\ No newline at end of file
index 90f98fa..598b561 100644 (file)
@@ -9,7 +9,7 @@
 
   <DATE>$LastChangedDate: 2007-11-15 13:33:00 +0200 (thu., 15 nov. 2007)$</DATE>
 
-  <SHORT_DESCRIPTION name="gettext">get text translated into the current locale.</SHORT_DESCRIPTION>
+  <SHORT_DESCRIPTION name="gettext">get text translated into the current locale and domain.</SHORT_DESCRIPTION>
 
   <CALLING_SEQUENCE>
     <CALLING_SEQUENCE_ITEM>msg=gettext(myString)</CALLING_SEQUENCE_ITEM>
@@ -30,7 +30,7 @@
   </PARAM>
 
   <DESCRIPTION>
-    <P><VERB>gettext</VERB> get the translation of a string to the current locale.</P>
+g    <P><VERB>gettext</VERB> get the translation of a string to the current locale in the current domain.</P>
   </DESCRIPTION>
 
   <EXAMPLE><![CDATA[
 gettext('Startup execution:')
  
   ]]></EXAMPLE>
-<!--
+
   <SEE_ALSO>
     <SEE_ALSO_ITEM>
-      <LINK>addtext</LINK>
+      <LINK>dgettext</LINK>
 
-      <LINK>removetext</LINK>
     </SEE_ALSO_ITEM>
   </SEE_ALSO>
--->
+
   <AUTHORS>
     <AUTHORS_ITEM>Sylvestre Ledru</AUTHORS_ITEM>
   </AUTHORS>
index 8ec7002..fdd6a75 100644 (file)
@@ -14,6 +14,7 @@ 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_getdefaultlanguage) _PARAMS((char *fname,unsigned long fname_len));
 int C2F(sci_gettext) _PARAMS((char *fname,unsigned long fname_len));
+int C2F(sci_dgettext) _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));
 
index 9717908..4f29d04 100644 (file)
@@ -13,7 +13,8 @@ static gw_generic_table Tab[]=
                {C2F(sci_getlanguage),"getlanguage"},
                {C2F(sci_getdefaultlanguage),"getdefaultlanguage"},
                {C2F(sci_gettext),"gettext"},
-               {C2F(sci_gettext),"_"}
+               {C2F(sci_gettext),"_"},
+               {C2F(sci_dgettext),"dgettext"}
 };
                        /*      {C2F(sci_getlanguagealias),"getlanguagealias"},
        {C2F(sci_getlanguagestable),"getlanguagestable"},
index dd36138..e9beac8 100644 (file)
@@ -19,15 +19,15 @@ int C2F(sci_gettext) _PARAMS((char *fname,unsigned long fname_len))
                {
                        static int l1,n1,m1;
 
-                       char *param1=NULL;
+                       char *msgid=NULL;
                        char *TranslatedString=NULL;
 
                        GetRhsVar(1,STRING_DATATYPE,&m1,&n1,&l1);
-                       param1=cstk(l1);
+                       msgid=cstk(l1);
 
                        /* We always have something from this functions because gettext
                         * is returning the same string if it cannot find it */
-                       TranslatedString=gettext(param1);
+                       TranslatedString=gettext(msgid);
 
                        n1=1;
                        CreateVarFromPtr(Rhs+1,STRING_DATATYPE,(m1=(int)strlen(TranslatedString), &m1),&n1,&TranslatedString);
@@ -37,7 +37,7 @@ int C2F(sci_gettext) _PARAMS((char *fname,unsigned long fname_len))
                }
        else
                {
-                       Scierror(999,"invalid first parameter. See help gettext.\n");
+                       Scierror(999,"%s: Wrong type for first input argument: String expected.\n",fname);
                        return 0;
                }
 }
index d3c892a..54b8024 100644 (file)
@@ -29,6 +29,7 @@
 <PRIMITIVE gatewayId="50" primitiveId="3" primitiveName="getdefaultlanguage" />
 <PRIMITIVE gatewayId="50" primitiveId="4" primitiveName="gettext" />
 <PRIMITIVE gatewayId="50" primitiveId="5" primitiveName="_" />
+<PRIMITIVE gatewayId="50" primitiveId="6" primitiveName="dgettext" />
 
 
 <!--<PRIMITIVE gatewayId="50" primitiveId="3" primitiveName="getlanguagealias" />
index 85bbaf9..aa1a6f4 100644 (file)
@@ -1,6 +1,6 @@
 /** 
-* INRIA 2007 
-* Rewrite using gettext by Sylvestre Ledru <sylvestre.ledru@inria.fr>
+* INRIA 2008
+* @author Sylvestre LEDRU
 */
 #include <string.h>
 #include <stdlib.h>
 #include "inisci-c.h"
 #include "scilabDefaults.h"
 #include "setgetlanguage.h"
-#include "../../../io/includes/setenvc.h"
 
 /*--------------------------------------------------------------------------*/ 
-/**
- * Export the variable LC_ALL to the system
- *
- * @param locale the locale (ex : fr_FR or en_US)
- */
-static void putEnvLC_ALL(char *locale){
-
-       /* It will put in the env something like LC_ALL=fr_FR */
-       if ( !setenvc(EXPORTENVLOCALE,locale))
-       {
-               fprintf(stderr,"Failed to declare the system variable LC_ALL\n");
-       }
-}
-
 
 BOOL InitializeLocalization(void)
 {
@@ -50,41 +35,31 @@ BOOL InitializeLocalization(void)
        char *pathLocales=NULL;
        char *ret=NULL;
 
-#ifndef _MSC_VER
-       ret=setlocale(LC_MESSAGES,"");
-#else
-       /* MS VS (setlocale) doesn't know LC_MESSAGES */
-       /* http://msdn2.microsoft.com/en-us/library/x99tb11d(vs.71).aspx */
-       ret = setlocale(LC_CTYPE,"");
-#endif
-       if (ret==NULL){
-               fprintf(stderr, "I18N: Doesn't support your locale.\n" );
-               return FALSE;
-       }
-
-       putEnvLC_ALL(ret);
-       setlanguage(ret, FALSE, FALSE);
+       setlanguage("", FALSE, FALSE); /* Booleans are : BOOL updateHelpIndex, BOOL updateMenus */
 
+       /* set directory containing message catalogs */
        pathLocales=(char *)MALLOC(sizeof(char)*(strlen(SCIpath)+strlen(PATHLOCALIZATIONFILE)+1));
 
        strcpy(pathLocales, SCIpath);
        strcat(pathLocales, PATHLOCALIZATIONFILE);
 
        if (bindtextdomain(NAMELOCALIZATIONDOMAIN,pathLocales)==NULL){
-               fprintf(stderr, "Error while binding the domain from %s\n", pathLocales);
+               fprintf(stderr, "Localization: Error while binding the domain from %s\n", pathLocales);
                FREE(pathLocales);
                return FALSE;
        }
        FREE(pathLocales);
 
-       if (textdomain(NAMELOCALIZATIONDOMAIN)==NULL){
-               fprintf(stderr, "Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
+       /* set domain for future gettext() calls */
+       ret=textdomain(NAMELOCALIZATIONDOMAIN);
+       if (ret==NULL){
+               fprintf(stderr, "Localization: Error while declaring the text domain %s\n", NAMELOCALIZATIONDOMAIN);
                return FALSE;
        }
 
        return TRUE;
 #else
-       fprintf(stderr, "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");
+       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");
        return FALSE;
 #endif
 }
index fcc347a..01414da 100644 (file)
@@ -1,15 +1,33 @@
 /*--------------------------------------------------------------------------*/
-/* INRIA 2007 */
-/* Allan CORNET */
+/* INRIA 2007/2008 */
+/* @author Allan CORNET */
+/* @author Sylvestre LEDRU */
 /*--------------------------------------------------------------------------*/
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include "machine.h"
+
+#ifndef _MSC_VER
+ #ifdef HAVE_LIBINTL_H
+  #include <libintl.h>
+  #ifdef HAVE_LOCALE_H
+   #include <locale.h>
+  #else
+   #error "Cannot find locale.h despite that libintl.h is available"
+  #endif
+ #endif
+#endif
+
 #include "setgetlanguage.h"
 #include "MALLOC.h"
 #include "tableslanguages.h"
 #include "defaultlanguage.h"
 #include "loadsavelanguage.h"
 #include "syncexec.h"
+#include "scilabDefaults.h"
+#include "../../../io/includes/setenvc.h"
+
 /*--------------------------------------------------------------------------*/
 static char CURRENTLANGUAGESTRING[LengthAlphacode]=SCILABDEFAULTLANGUAGE;
 static int  CURRENTLANGUAGECODE=SCILABDEFAULTLANGUAGECODE;
@@ -17,6 +35,7 @@ static int  CURRENTLANGUAGECODE=SCILABDEFAULTLANGUAGECODE;
 static int FindLanguageCode(char *lang);
 static BOOL setlanguagecode(char *lang);
 static char *FindAlias(char *lang);
+static void putEnvLC_ALL(char *locale);
 static char *GetLanguageFromAlias(char *langAlias);
 /*--------------------------------------------------------------------------*/
 BOOL setlanguage(char *lang,BOOL updateHelpIndex, BOOL updateMenus)
@@ -28,8 +47,30 @@ BOOL setlanguage(char *lang,BOOL updateHelpIndex, BOOL updateMenus)
                {
                        if (needtochangelanguage(lang))
                        {
+                               char *ret=NULL;
+
+                               /* Load the locale from the system */
+#ifndef _MSC_VER
+                               ret=setlocale(LC_MESSAGES,lang);
+#else
+                               /* MS VS (setlocale) doesn't know LC_MESSAGES */
+                               /* http://msdn2.microsoft.com/en-us/library/x99tb11d(vs.71).aspx */
+                               ret = setlocale(LC_CTYPE,lang);
+#endif
+                               if (ret==NULL){
+                                       fprintf(stderr, "Localization: Doesn't support the locale '%s'.\n",lang);
+                                       return FALSE;
+                               }
+                               
+                               putEnvLC_ALL(lang);
+
                                /* change language */
-                               strcpy(CURRENTLANGUAGESTRING,lang);
+                               if (strcmp(lang,"C")==0){
+                                       /* The lang is the default one... ie en_US */
+                                       strcpy(CURRENTLANGUAGESTRING,"en_US");
+                               }else{
+                                       strcpy(CURRENTLANGUAGESTRING,lang);
+                               }
                                setlanguagecode(lang);
 
                                if (updateHelpIndex)
@@ -178,7 +219,7 @@ char *convertlanguagealias(char *strlanguage)
 {
        char *correctlanguage=NULL;
 
-       if (strlen(strlanguage)==2)
+       if ( (strlen(strlanguage)==2) || (strcmp(strlanguage,"en_US")==0) ) /* If the user wants to change to en_US ... use the default locale */
        {
                correctlanguage=GetLanguageFromAlias(strlanguage);
        }
@@ -189,3 +230,16 @@ char *convertlanguagealias(char *strlanguage)
        return correctlanguage;
 }
 /*--------------------------------------------------------------------------*/
+/**
+ * Export the variable LC_ALL to the system
+ *
+ * @param locale the locale (ex : fr_FR or en_US)
+ */
+static void putEnvLC_ALL(char *locale){
+
+       /* It will put in the env something like LC_ALL=fr_FR */
+       if ( !setenvc(EXPORTENVLOCALE,locale))
+       {
+               fprintf(stderr,"Localization: Failed to declare the system variable LC_ALL\n");
+       }
+}
index a900888..9c1d16f 100644 (file)
@@ -29,7 +29,7 @@ typedef struct languagesalias_struct
 
 } LanguagesTableAlias;
 /*--------------------------------------------------------------------------*/
-#define NumberLanguagesAlias 41
+#define NumberLanguagesAlias 42
 static LanguagesTableAlias LANGUAGE_LOCALE_ALIAS[NumberLanguagesAlias]=
 {
        {"bg","bg_BG"},
@@ -40,7 +40,8 @@ static LanguagesTableAlias LANGUAGE_LOCALE_ALIAS[NumberLanguagesAlias]=
        {"da","da_DK"},
        {"de","de_DE"},
        {"el","el_GR"},
-       {"en","en_US"},
+       {"en","C"}, /* When the user is requesting english ... switch back to the default */
+       {"en_US","C"},
        {"es","es_ES"},
        {"et","et_EE"},
        {"eu","eu_ES"},
@@ -75,7 +76,7 @@ static LanguagesTableAlias LANGUAGE_LOCALE_ALIAS[NumberLanguagesAlias]=
        {"uk","uk_UA"}
 };
 /*--------------------------------------------------------------------------*/
-#define NumberLanguages 219
+#define NumberLanguages 220
 static LanguagesTable LANGUAGE_COUNTRY_TAB[NumberLanguages]=
 {
        {  1, "aa_DJ","Afar (Djibouti)"},
@@ -296,7 +297,8 @@ static LanguagesTable LANGUAGE_COUNTRY_TAB[NumberLanguages]=
        { 216,"uz_Latn","Uzbek (Latin)"},
        { 217,"vi_VN","Vietnamese (Vietnam)"},
        { 218,"wal_ET","Walamo (Ethiopia)"},
-       { 219,"cy_GB","Welsh (United Kingdom)"}
+       { 219,"cy_GB","Welsh (United Kingdom)"},
+       { 220,"C","English (Default)"}
 };
 /*--------------------------------------------------------------------------*/
 #endif /* __TABLESLANGUAGES_H__ */
diff --git a/scilab/modules/localization/tests/unit_tests/dgettext.dia.ref b/scilab/modules/localization/tests/unit_tests/dgettext.dia.ref
new file mode 100644 (file)
index 0000000..ecc06ea
--- /dev/null
@@ -0,0 +1,31 @@
+//===============================
+// unit tests dgettext
+// INRIA 2008
+// @author Sylvestre LEDRU
+//===============================
+// Void call
+if execstr('dgettext()','errcatch')==0 then bugmes();quit;end
+// one input argument
+str1="plop"; if execstr('dgettext(str1)','errcatch')==0 then bugmes();quit;end
+// three input argument
+str1="plop"; str2="plip"; str3="plup"; if execstr('gettext(str1, str2, str3)','errcatch')==0 then bugmes();quit;end
+// Try to translate from en_US to en_US to domain/string which doesn't exist
+lang="en_US"; setlanguage(lang); domain="fake_domain"; msg="Localization does not exist"; if dgettext(domain,msg) <> msg then pause, end
+// Try to translate from en_US to fr_FR to a domain/string which doesn't exist
+lang="fr_FR"; setlanguage(lang); domain="fake_domain"; msg="Localization does not exist"; if dgettext(domain,msg) <> msg then pause, end
+// Check if it is working with a good domain & good msgid
+lang="fr_FR"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> "Initialisation:" then pause, end
+// Check if it is working with a bad domain & good msgid
+lang="fr_FR"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) == "Initialisation:" then pause, end
+// Check if it is working with a good domain & good msgid and alias
+lang="fr"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> "Initialisation:" then pause, end
+// Check if it is working with a bad domain & good msgid and alias
+lang="fr"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) == "Initialisation:" then pause, end
+// Check if it is working with a good domain & good msgid
+lang="en_US"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+// Check if it is working with a bad domain & good msgid
+lang="en_US"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+// Check if it is working with a good domain & good msgid and alias
+lang="en"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+// Check if it is working with a bad domain & good msgid and alias
+lang="en"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
diff --git a/scilab/modules/localization/tests/unit_tests/dgettext.tst b/scilab/modules/localization/tests/unit_tests/dgettext.tst
new file mode 100644 (file)
index 0000000..45d6549
--- /dev/null
@@ -0,0 +1,49 @@
+//===============================
+// unit tests dgettext
+// INRIA 2008
+// @author Sylvestre LEDRU
+//===============================
+
+// Void call
+if execstr('dgettext()','errcatch')==0 then pause,end
+
+// one input argument
+str1="plop"; if execstr('dgettext(str1)','errcatch')==0 then pause,end
+
+// three input argument
+str1="plop"; str2="plip"; str3="plup"; if execstr('gettext(str1, str2, str3)','errcatch')==0 then pause,end
+
+// Try to translate from en_US to en_US to domain/string which doesn't exist
+lang="en_US"; setlanguage(lang); domain="fake_domain"; msg="Localization does not exist"; if dgettext(domain,msg) <> msg then pause, end
+
+// Try to translate from en_US to fr_FR to a domain/string which doesn't exist
+lang="fr_FR"; setlanguage(lang); domain="fake_domain"; msg="Localization does not exist"; if dgettext(domain,msg) <> msg then pause, end
+
+
+// Check if it is working with a good domain & good msgid
+lang="fr_FR"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> "Initialisation:" then pause, end
+
+// Check if it is working with a bad domain & good msgid
+lang="fr_FR"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) == "Initialisation:" then pause, end
+
+// Check if it is working with a good domain & good msgid and alias
+lang="fr"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> "Initialisation:" then pause, end
+
+// Check if it is working with a bad domain & good msgid and alias
+lang="fr"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) == "Initialisation:" then pause, end
+
+
+// Check if it is working with a good domain & good msgid
+lang="en_US"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+
+// Check if it is working with a bad domain & good msgid
+lang="en_US"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+
+// Check if it is working with a good domain & good msgid and alias
+lang="en"; setlanguage(lang); domain="scilab"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+
+// Check if it is working with a bad domain & good msgid and alias
+lang="en"; setlanguage(lang); domain="fake_domain"; msg="Startup execution:"; if dgettext(domain,msg) <> msg then pause, end
+
+// @TODO : 
+// Add test to use other domain which are working (ie not fake_domain)
index fe5c34a..1fe823a 100644 (file)
@@ -16,5 +16,6 @@ lang="en_US"; setlanguage(lang); if getlanguage() <> "en_US" then pause, end
 // Switch to french with full code
 lang="fr_FR"; setlanguage(lang); if getlanguage() <> "fr_FR" then pause, end
 
-// Switch to default lang by calling a wrong lang
-lang="ffff"; setlanguage(lang); if getlanguage() <> "en_US" then pause, end
+// Stay in the curretn lang when calling a wrong lang
+lang="ffff"; setlanguage(lang); if getlanguage() <> "fr_FR" then pause, end
+
diff --git a/scilab/modules/localization/tests/unit_tests/gettext.dia.ref b/scilab/modules/localization/tests/unit_tests/gettext.dia.ref
new file mode 100644 (file)
index 0000000..7264fea
--- /dev/null
@@ -0,0 +1,17 @@
+//===============================
+// unit tests gettext
+// INRIA 2008
+// @author Sylvestre LEDRU
+//===============================
+// Void call
+if execstr('gettext()','errcatch')==0 then bugmes();quit;end
+// two inputs arguments
+str1="plop"; str2="plip"; if execstr('gettext(str1, str2)','errcatch')==0 then bugmes();quit;end
+// Try to translate from en_US to en_US to a string which doesn't exist
+lang="en_US"; setlanguage(lang); msg="Localization does not exist"; if gettext(msg) <> msg then pause, end
+// Try to translate from en_US to fr_FR to a string which doesn't exist
+lang="fr_FR"; setlanguage(lang); msg="Localization does not exist"; if gettext(msg) <> msg then pause, end
+lang="fr_FR"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> "Initialisation:" then pause, end
+lang="fr"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> "Initialisation:" then pause, end
+lang="en"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> msg then pause, end
+lang="en_US"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> msg then pause, end
diff --git a/scilab/modules/localization/tests/unit_tests/gettext.tst b/scilab/modules/localization/tests/unit_tests/gettext.tst
new file mode 100644 (file)
index 0000000..f60d224
--- /dev/null
@@ -0,0 +1,26 @@
+//===============================
+// unit tests gettext
+// INRIA 2008
+// @author Sylvestre LEDRU
+//===============================
+
+// Void call
+if execstr('gettext()','errcatch')==0 then pause,end
+
+// two inputs arguments
+str1="plop"; str2="plip"; if execstr('gettext(str1, str2)','errcatch')==0 then pause,end
+
+// Try to translate from en_US to en_US to a string which doesn't exist
+lang="en_US"; setlanguage(lang); msg="Localization does not exist"; if gettext(msg) <> msg then pause, end
+
+// Try to translate from en_US to fr_FR to a string which doesn't exist
+lang="fr_FR"; setlanguage(lang); msg="Localization does not exist"; if gettext(msg) <> msg then pause, end
+
+lang="fr_FR"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> "Initialisation:" then pause, end
+
+lang="fr"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> "Initialisation:" then pause, end
+
+lang="en"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> msg then pause, end
+
+lang="en_US"; setlanguage(lang); msg="Startup execution:"; if gettext(msg) <> msg then pause, end
+