Some language like english, french and spanish to name a few, are spoken in different countries. The user's computer produce different localization string for each basic language and country combination.
 
AbiWord adapt it's menu and toolbar to the localization string. For example, if the localization string is "fr-CA" for french canadian, the program first search a "fr-CA" language. It can't find that language, since it is not supported. The program then search for the "fr" default language. Finding the "fr-FR" default language, the menus and toolbar will be set to French. This algorithm makes the program more user friendly than having to configure the "AbiWord.Profile" configuration file. The configuration file can be used, if the user want to override the language setting.
 
The StringSet does not completly follow this algorithm. It does not search for the default language. The patch I am proposing does it. So now, the dialog strings follow the same language as menus instead of reverting to the builtin english dialogs.
 
The bulk of StringSet language selection code is implented on platform specific code. For me, it is on file ap_Win32App.cpp on Windows. Other platforms are quite similar, so I made changes for those too, even thought I could not test it. The patch is in two files, one for Windows the other for Unix, BeOS and QNX. The Windows file should be applied first, it contains also some cross-platform code.  Developpers on other platforms may then test it.
 
 
Gilles
Index: abi/src/wp/ap/beos/ap_BeOSApp.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/beos/ap_BeOSApp.cpp,v
retrieving revision 1.38
diff -u -r1.38 ap_BeOSApp.cpp
--- abi/src/wp/ap/beos/ap_BeOSApp.cpp   2000/10/30 20:52:26     1.38
+++ abi/src/wp/ap/beos/ap_BeOSApp.cpp   2000/11/19 02:06:41
@@ -55,6 +55,7 @@
 #include "xap_EditMethods.h"
 #include "ap_LoadBindings.h"
 #include "xap_Menu_ActionSet.h"
+#include "xap_Menu_LabelSet.h"
 #include "xap_Toolbar_ActionSet.h"       
 
 #include "ie_imp.h"
@@ -300,6 +301,31 @@
                                        ((szDirectory[strlen(szDirectory)-1]=='/') ? 
"" : "/"),
                                        szStringSet);
 
+                       // try finding the default set name for this language.
+                       UT_uint32 k, iLanguageCount = 
+AP_GetMenuLabelSetLanguageCount();
+                       char * dash = strchr(szStringSet, '-');
+                       int len = (dash ? dash - szStringSet : 2);
+                       const char * szDefaultStringSetForLanguage = "";
+                       for (k=0; k < iLanguageCount; k++)
+                       {
+                               if (   
+(UT_strnicmp(szStringSet,AP_GetNthMenuLabelLanguageName(k),len)==0)
+                                       && (AP_IsNthMenuLabelDefaultSetForLanguage(k)))
+                               {
+                                       szDefaultStringSetForLanguage = 
+AP_GetNthMenuLabelLanguageName(k);
+                                       break;
+                               }
+                       }
+
+                       // build the path for this default set language name
+                       char * szPathnameDefaultSetForLanguage = 
+                               (char *)calloc(sizeof(char),strlen(szDirectory)+
+                               strlen(szDefaultStringSetForLanguage)+100);
+                       UT_ASSERT(szPathname);
+                       sprintf(szPathnameDefaultSetForLanguage,"%s%s%s.strings",
+                                       szDirectory,
+                                       ((szDirectory[strlen(szDirectory)-1]=='\\') ? 
+"" : "\\"),
+                                       szDefaultStringSetForLanguage);
+
                        AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
                        UT_ASSERT(pDiskStringSet);
 
@@ -309,12 +335,23 @@
                                m_pStringSet = pDiskStringSet;
                                UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
                        }
+                       else if (*szDefaultStringSetForLanguage && 
+                               
+pDiskStringSet->loadStringsFromDisk(szPathnameDefaultSetForLanguage))
+                       {
+                               pDiskStringSet->setFallbackStringSet(m_pStringSet);
+                               m_pStringSet = pDiskStringSet;
+                               m_prefs->getCurrentScheme()->setValue(
+                                       
+AP_PREF_KEY_StringSet,szDefaultStringSetForLanguage);
+                               UT_DEBUGMSG(("Using default StringSet for language 
+[%s]\n",
+                                       szPathnameDefaultSetForLanguage));
+                       }
                        else
                        {
                                DELETEP(pDiskStringSet);
                                UT_DEBUGMSG(("Unable to load StringSet [%s] -- using 
builtin strings instead.\n",szPathname));
                        }
                                
+                       free(szPathnameDefaultSetForLanguage);
                        free(szPathname);
                }
        }
Index: abi/src/wp/ap/qnx/ap_QNXApp.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/qnx/ap_QNXApp.cpp,v
retrieving revision 1.18
diff -u -r1.18 ap_QNXApp.cpp
--- abi/src/wp/ap/qnx/ap_QNXApp.cpp     2000/11/15 23:57:41     1.18
+++ abi/src/wp/ap/qnx/ap_QNXApp.cpp     2000/11/19 02:06:49
@@ -49,6 +49,7 @@
 #include "xap_Dlg_MessageBox.h"
 #include "xap_Dialog_Id.h"
 #include "xap_Menu_ActionSet.h"
+#include "xap_Menu_LabelSet.h"
 #include "xap_Toolbar_ActionSet.h"
 #include "xav_View.h"
 
@@ -214,6 +215,31 @@
                                        ((szDirectory[strlen(szDirectory)-1]=='/') ? 
"" : "/"),
                                        szStringSet);
 
+                       // try finding the default set name for this language.
+                       UT_uint32 k, iLanguageCount = 
+AP_GetMenuLabelSetLanguageCount();
+                       char * dash = strchr(szStringSet, '-');
+                       int len = (dash ? dash - szStringSet : 2);
+                       const char * szDefaultStringSetForLanguage = "";
+                       for (k=0; k < iLanguageCount; k++)
+                       {
+                               if (   
+(UT_strnicmp(szStringSet,AP_GetNthMenuLabelLanguageName(k),len)==0)
+                                       && (AP_IsNthMenuLabelDefaultSetForLanguage(k)))
+                               {
+                                       szDefaultStringSetForLanguage = 
+AP_GetNthMenuLabelLanguageName(k);
+                                       break;
+                               }
+                       }
+
+                       // build the path for this default set language name
+                       char * szPathnameDefaultSetForLanguage = 
+                               (char *)calloc(sizeof(char),strlen(szDirectory)+
+                               strlen(szDefaultStringSetForLanguage)+100);
+                       UT_ASSERT(szPathname);
+                       sprintf(szPathnameDefaultSetForLanguage,"%s%s%s.strings",
+                                       szDirectory,
+                                       ((szDirectory[strlen(szDirectory)-1]=='\\') ? 
+"" : "\\"),
+                                       szDefaultStringSetForLanguage);
+
                        AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
                        UT_ASSERT(pDiskStringSet);
 
@@ -223,12 +249,23 @@
                                m_pStringSet = pDiskStringSet;
                                UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
                        }
+                       else if (*szDefaultStringSetForLanguage && 
+                               
+pDiskStringSet->loadStringsFromDisk(szPathnameDefaultSetForLanguage))
+                       {
+                               pDiskStringSet->setFallbackStringSet(m_pStringSet);
+                               m_pStringSet = pDiskStringSet;
+                               m_prefs->getCurrentScheme()->setValue(
+                                       
+AP_PREF_KEY_StringSet,szDefaultStringSetForLanguage);
+                               UT_DEBUGMSG(("Using default StringSet for language 
+[%s]\n",
+                                       szPathnameDefaultSetForLanguage));
+                       }
                        else
                        {
                                DELETEP(pDiskStringSet);
                                UT_DEBUGMSG(("Unable to load StringSet [%s] -- using 
builtin strings instead.\n",szPathname));
                        }
                                
+                       free(szPathnameDefaultSetForLanguage);
                        free(szPathname);
                }
        }
Index: abi/src/wp/ap/unix/ap_UnixApp.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/unix/ap_UnixApp.cpp,v
retrieving revision 1.63
diff -u -r1.63 ap_UnixApp.cpp
--- abi/src/wp/ap/unix/ap_UnixApp.cpp   2000/11/14 05:03:49     1.63
+++ abi/src/wp/ap/unix/ap_UnixApp.cpp   2000/11/19 02:06:56
@@ -49,6 +49,7 @@
 #include "xap_Dlg_MessageBox.h"
 #include "xap_Dialog_Id.h"
 #include "xap_Menu_ActionSet.h"
+#include "xap_Menu_LabelSet.h"
 #include "xap_Toolbar_ActionSet.h"
 #include "xav_View.h"
 
@@ -216,6 +217,31 @@
                                        ((szDirectory[strlen(szDirectory)-1]=='/') ? 
"" : "/"),
                                        szStringSet);
 
+                       // try finding the default set name for this language.
+                       UT_uint32 k, iLanguageCount = 
+AP_GetMenuLabelSetLanguageCount();
+                       char * dash = strchr(szStringSet, '-');
+                       int len = (dash ? dash - szStringSet : 2);
+                       const char * szDefaultStringSetForLanguage = "";
+                       for (k=0; k < iLanguageCount; k++)
+                       {
+                               if (   
+(UT_strnicmp(szStringSet,AP_GetNthMenuLabelLanguageName(k),len)==0)
+                                       && (AP_IsNthMenuLabelDefaultSetForLanguage(k)))
+                               {
+                                       szDefaultStringSetForLanguage = 
+AP_GetNthMenuLabelLanguageName(k);
+                                       break;
+                               }
+                       }
+
+                       // build the path for this default set language name
+                       char * szPathnameDefaultSetForLanguage = 
+                               (char *)calloc(sizeof(char),strlen(szDirectory)+
+                               strlen(szDefaultStringSetForLanguage)+100);
+                       UT_ASSERT(szPathname);
+                       sprintf(szPathnameDefaultSetForLanguage,"%s%s%s.strings",
+                                       szDirectory,
+                                       ((szDirectory[strlen(szDirectory)-1]=='\\') ? 
+"" : "\\"),
+                                       szDefaultStringSetForLanguage);
+
                        AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
                        UT_ASSERT(pDiskStringSet);
 
@@ -225,12 +251,23 @@
                                m_pStringSet = pDiskStringSet;
                                UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
                        }
+                       else if (*szDefaultStringSetForLanguage && 
+                               
+pDiskStringSet->loadStringsFromDisk(szPathnameDefaultSetForLanguage))
+                       {
+                               pDiskStringSet->setFallbackStringSet(m_pStringSet);
+                               m_pStringSet = pDiskStringSet;
+                               m_prefs->getCurrentScheme()->setValue(
+                                       
+AP_PREF_KEY_StringSet,szDefaultStringSetForLanguage);
+                               UT_DEBUGMSG(("Using default StringSet for language 
+[%s]\n",
+                                       szPathnameDefaultSetForLanguage));
+                       }
                        else
                        {
                                DELETEP(pDiskStringSet);
                                UT_DEBUGMSG(("Unable to load StringSet [%s] -- using 
builtin strings instead.\n",szPathname));
                        }
                                
+                       free(szPathnameDefaultSetForLanguage);
                        free(szPathname);
                }
        }
Index: abi/src/af/xap/xp/xap_Menu_LabelSet.h
===================================================================
RCS file: /cvsroot/abi/src/af/xap/xp/xap_Menu_LabelSet.h,v
retrieving revision 1.5
diff -u -r1.5 xap_Menu_LabelSet.h
--- abi/src/af/xap/xp/xap_Menu_LabelSet.h       1999/05/01 08:45:48     1.5
+++ abi/src/af/xap/xp/xap_Menu_LabelSet.h       2000/11/19 02:06:29
@@ -26,5 +26,6 @@
 EV_Menu_LabelSet * AP_CreateMenuLabelSet(const char * szLanguage);
 UT_uint32 AP_GetMenuLabelSetLanguageCount(void);
 const char * AP_GetNthMenuLabelLanguageName(UT_uint32 ndx);
+UT_Bool AP_IsNthMenuLabelDefaultSetForLanguage(UT_uint32 ndx);
 
 #endif /* XAP_MENU_LABELSET_H */
Index: abi/src/wp/ap/win/ap_Win32App.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/win/ap_Win32App.cpp,v
retrieving revision 1.50
diff -u -r1.50 ap_Win32App.cpp
--- abi/src/wp/ap/win/ap_Win32App.cpp   2000/07/10 21:56:16     1.50
+++ abi/src/wp/ap/win/ap_Win32App.cpp   2000/11/19 02:07:02
@@ -42,6 +42,7 @@
 #include "xap_EditMethods.h"
 #include "ap_LoadBindings.h"
 #include "xap_Menu_ActionSet.h"
+#include "xap_Menu_LabelSet.h"
 #include "xap_Toolbar_ActionSet.h"
 
 #include "ap_Win32Resources.rc2"
@@ -194,6 +195,31 @@
                                        ((szDirectory[strlen(szDirectory)-1]=='\\') ? 
"" : "\\"),
                                        szStringSet);
 
+                       // try finding the default set name for this language.
+                       UT_uint32 k, iLanguageCount = 
+AP_GetMenuLabelSetLanguageCount();
+                       char * dash = strchr(szStringSet, '-');
+                       int len = (dash ? dash - szStringSet : 2);
+                       const char * szDefaultStringSetForLanguage = "";
+                       for (k=0; k < iLanguageCount; k++)
+                       {
+                               if (   
+(UT_strnicmp(szStringSet,AP_GetNthMenuLabelLanguageName(k),len)==0)
+                                       && (AP_IsNthMenuLabelDefaultSetForLanguage(k)))
+                               {
+                                       szDefaultStringSetForLanguage = 
+AP_GetNthMenuLabelLanguageName(k);
+                                       break;
+                               }
+                       }
+
+                       // build the path for this default set language name
+                       char * szPathnameDefaultSetForLanguage = 
+                               (char *)calloc(sizeof(char),strlen(szDirectory)+
+                               strlen(szDefaultStringSetForLanguage)+100);
+                       UT_ASSERT(szPathname);
+                       sprintf(szPathnameDefaultSetForLanguage,"%s%s%s.strings",
+                                       szDirectory,
+                                       ((szDirectory[strlen(szDirectory)-1]=='\\') ? 
+"" : "\\"),
+                                       szDefaultStringSetForLanguage);
+
                        AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this);
                        UT_ASSERT(pDiskStringSet);
 
@@ -203,12 +229,23 @@
                                m_pStringSet = pDiskStringSet;
                                UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname));
                        }
+                       else if (*szDefaultStringSetForLanguage && 
+                               
+pDiskStringSet->loadStringsFromDisk(szPathnameDefaultSetForLanguage))
+                       {
+                               pDiskStringSet->setFallbackStringSet(m_pStringSet);
+                               m_pStringSet = pDiskStringSet;
+                               m_prefs->getCurrentScheme()->setValue(
+                                       
+AP_PREF_KEY_StringSet,szDefaultStringSetForLanguage);
+                               UT_DEBUGMSG(("Using default StringSet for language 
+[%s]\n",
+                                       szPathnameDefaultSetForLanguage));
+                       }
                        else
                        {
                                DELETEP(pDiskStringSet);
                                UT_DEBUGMSG(("Unable to load StringSet [%s] -- using 
builtin strings instead.\n",szPathname));
                        }
                                
+                       free(szPathnameDefaultSetForLanguage);
                        free(szPathname);
                }
        }
Index: abi/src/wp/ap/xp/ap_Menu_LabelSet.cpp
===================================================================
RCS file: /cvsroot/abi/src/wp/ap/xp/ap_Menu_LabelSet.cpp,v
retrieving revision 1.12
diff -u -r1.12 ap_Menu_LabelSet.cpp
--- abi/src/wp/ap/xp/ap_Menu_LabelSet.cpp       2000/10/10 00:39:32     1.12
+++ abi/src/wp/ap/xp/ap_Menu_LabelSet.cpp       2000/11/19 02:07:10
@@ -149,3 +149,10 @@
        return s_ltTable[ndx].m_name;
 }
 
+UT_Bool AP_IsNthMenuLabelDefaultSetForLanguage(UT_uint32 ndx)
+{
+       UT_ASSERT(ndx < NrElements(s_ltTable));
+
+       return s_ltTable[ndx].m_bIsDefaultSetForLanguage;
+}
+

Reply via email to