simplified message catalog search code using the new wxStandardPaths::GetLocalizedResourcesDir()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38371 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-03-25 18:28:29 +00:00
parent 3af9f2de59
commit f830b2b1fc

View File

@@ -77,6 +77,7 @@
#include "wx/ptr_scpd.h" #include "wx/ptr_scpd.h"
#include "wx/app.h" #include "wx/app.h"
#include "wx/apptrait.h" #include "wx/apptrait.h"
#include "wx/stdpaths.h"
#if defined(__WXMAC__) #if defined(__WXMAC__)
#include "wx/mac/private.h" // includes mac headers #include "wx/mac/private.h" // includes mac headers
@@ -984,7 +985,7 @@ private:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// the list of the directories to search for message catalog files // the list of the directories to search for message catalog files
static wxArrayString s_searchPrefixes; static wxArrayString gs_searchPrefixes;
// ============================================================================ // ============================================================================
// implementation // implementation
@@ -1005,18 +1006,19 @@ wxMsgCatalogFile::~wxMsgCatalogFile()
wxDELETEA(m_pData); wxDELETEA(m_pData);
} }
// return all directories to search for given prefix // return the directory to search for message catalogs under the given prefix
static wxString GetAllMsgCatalogSubdirs(const wxChar *prefix, static
const wxChar *lang) wxString GetMsgCatalogSubdir(const wxChar *prefix, const wxChar *lang)
{ {
wxString searchPath; wxString searchPath;
searchPath << prefix << wxFILE_SEP_PATH << lang;
// search first in prefix/fr/LC_MESSAGES, then in prefix/fr and finally in // under Unix, the message catalogs are supposed to go into LC_MESSAGES
// prefix (assuming the language is 'fr') // subdirectory but there is no such requirement/tradition on the other
searchPath << prefix << wxFILE_SEP_PATH << lang << wxFILE_SEP_PATH // systems
<< wxT("LC_MESSAGES") << wxPATH_SEP #ifdef __UNIX__
<< prefix << wxFILE_SEP_PATH << lang << wxPATH_SEP searchPath << wxFILE_SEP_PATH << wxT("LC_MESSAGES");
<< prefix << wxPATH_SEP; #endif
return searchPath; return searchPath;
} }
@@ -1024,48 +1026,59 @@ static wxString GetAllMsgCatalogSubdirs(const wxChar *prefix,
// construct the search path for the given language // construct the search path for the given language
static wxString GetFullSearchPath(const wxChar *lang) static wxString GetFullSearchPath(const wxChar *lang)
{ {
wxString searchPath;
// first take the entries explicitly added by the program // first take the entries explicitly added by the program
size_t count = s_searchPrefixes.Count(); wxArrayString paths;
for ( size_t n = 0; n < count; n++ ) paths.reserve(gs_searchPrefixes.size() + 1);
size_t n,
count = gs_searchPrefixes.size();
for ( n = 0; n < count; n++ )
{ {
searchPath << GetAllMsgCatalogSubdirs(s_searchPrefixes[n], lang) paths.Add(GetMsgCatalogSubdir(gs_searchPrefixes[n], lang));
<< wxPATH_SEP;
} }
// TODO: use wxStandardPaths instead of all this mess!!
#if wxUSE_STDPATHS
// then look in the standard location
const wxString stdp = wxStandardPaths::Get().
GetLocalizedResourcesDir(lang, wxStandardPaths::ResourceCat_Messages);
if ( paths.Index(stdp) == wxNOT_FOUND )
paths.Add(stdp);
#endif // wxUSE_STDPATHS
// last look in default locations
#ifdef __UNIX__
// LC_PATH is a standard env var containing the search path for the .mo // LC_PATH is a standard env var containing the search path for the .mo
// files // files
#ifndef __WXWINCE__
const wxChar *pszLcPath = wxGetenv(wxT("LC_PATH")); const wxChar *pszLcPath = wxGetenv(wxT("LC_PATH"));
if ( pszLcPath != NULL ) if ( pszLcPath )
searchPath << GetAllMsgCatalogSubdirs(pszLcPath, lang); {
#endif const wxString lcp = GetMsgCatalogSubdir(pszLcPath, lang);
if ( paths.Index(lcp) == wxNOT_FOUND )
paths.Add(lcp);
}
#ifdef __UNIX__ // also add the one from where wxWin was installed:
// add some standard ones and the one in the tree where wxWin was installed: wxString wxp = wxGetInstallPrefix();
searchPath if ( !wxp.empty() )
<< GetAllMsgCatalogSubdirs(wxString(wxGetInstallPrefix()) + wxT("/share/locale"), lang) {
<< GetAllMsgCatalogSubdirs(wxT("/usr/share/locale"), lang) wxp = GetMsgCatalogSubdir(wxp + _T("/share/locale"), lang);
<< GetAllMsgCatalogSubdirs(wxT("/usr/lib/locale"), lang) if ( paths.Index(wxp) == wxNOT_FOUND )
<< GetAllMsgCatalogSubdirs(wxT("/usr/local/share/locale"), lang); paths.Add(wxp);
}
#endif // __UNIX__ #endif // __UNIX__
// then take the current directory
// FIXME it should be the directory of the executable // finally construct the full search path
#if defined(__WXMAC__) wxString searchPath;
searchPath << GetAllMsgCatalogSubdirs(wxGetCwd(), lang); searchPath.reserve(500);
// generic search paths could be somewhere in the system folder preferences count = paths.size();
#elif defined(__WXMSW__) for ( n = 0; n < count; n++ )
// look in the directory of the executable {
wxString path; searchPath += paths[n];
wxSplitPath(wxGetFullModuleName(), &path, NULL, NULL); if ( n != count - 1 )
searchPath << GetAllMsgCatalogSubdirs(path, lang); searchPath += wxPATH_SEP;
#else // !Mac, !MSW }
searchPath << GetAllMsgCatalogSubdirs(wxT("."), lang);
#endif // platform
return searchPath; return searchPath;
} }
@@ -1098,9 +1111,9 @@ bool wxMsgCatalogFile::Load(const wxChar *szDirPrefix, const wxChar *szName,
// also add just base locale name: for things like "fr_BE" (belgium // also add just base locale name: for things like "fr_BE" (belgium
// french) we should use "fr" if no belgium specific message catalogs // french) we should use "fr" if no belgium specific message catalogs
// exist // exist
searchPath << GetFullSearchPath(wxString(szDirPrefix). searchPath << wxPATH_SEP
Left((size_t)(sublocale - szDirPrefix))) << GetFullSearchPath(wxString(szDirPrefix).
<< wxPATH_SEP; Left((size_t)(sublocale - szDirPrefix)));
} }
// don't give translation errors here because the wxstd catalog might // don't give translation errors here because the wxstd catalog might
@@ -1818,9 +1831,9 @@ bool wxLocale::Init(int language, int flags)
void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix) void wxLocale::AddCatalogLookupPathPrefix(const wxString& prefix)
{ {
if ( s_searchPrefixes.Index(prefix) == wxNOT_FOUND ) if ( gs_searchPrefixes.Index(prefix) == wxNOT_FOUND )
{ {
s_searchPrefixes.Add(prefix); gs_searchPrefixes.Add(prefix);
} }
//else: already have it //else: already have it
} }