// Michael N. Filippov <michael@idisys.iae.nsk.su>
// (2003/09/30 - PluralForms support)
// Created: 2010-04-23
-// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/tokenzr.h"
#include "wx/fontmap.h"
#include "wx/stdpaths.h"
-#include "wx/hashset.h"
+#include "wx/private/threadinfo.h"
#ifdef __WINDOWS__
#include "wx/dynlib.h"
wxLogTrace(TRACE_I18N, "%s: [%s]", prefix, wxJoin(arr, ','));
}
-void LogTraceLargeArray(const char *prefix, const wxArrayString& arr)
+void LogTraceLargeArray(const wxString& prefix, const wxArrayString& arr)
{
wxLogTrace(TRACE_I18N, "%s:", prefix);
for ( wxArrayString::const_iterator i = arr.begin(); i != arr.end(); ++i )
wxS("adding '%s' translation for domain '%s' (msgid language '%s')"),
domain_lang, domain, msgIdLang);
- // It is OK to not load catalog if the msgid language and m_language match,
- // in which case we can directly display the texts embedded in program's
- // source code:
- if ( msgIdLang == domain_lang )
- return true;
-
- return LoadCatalog(domain, domain_lang);
+ return LoadCatalog(domain, domain_lang, msgIdLang);
}
-bool wxTranslations::LoadCatalog(const wxString& domain, const wxString& lang)
+bool wxTranslations::LoadCatalog(const wxString& domain, const wxString& lang, const wxString& msgIdLang)
{
wxCHECK_MSG( m_loader, false, "loader can't be NULL" );
cat = m_loader->LoadCatalog(domain, baselang);
}
+ if ( !cat )
+ {
+ // It is OK to not load catalog if the msgid language and m_language match,
+ // in which case we can directly display the texts embedded in program's
+ // source code:
+ if ( msgIdLang == lang )
+ return true;
+ }
+
if ( cat )
{
// add it to the head of the list so that in GetString it will
}
-namespace
-{
-WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
- wxLocaleUntranslatedStrings);
-}
-
/* static */
const wxString& wxTranslations::GetUntranslatedString(const wxString& str)
{
- static wxLocaleUntranslatedStrings s_strings;
+ wxLocaleUntranslatedStrings& strings = wxThreadInfo.untranslatedStrings;
- wxLocaleUntranslatedStrings::iterator i = s_strings.find(str);
- if ( i == s_strings.end() )
- return *s_strings.insert(str).first;
+ wxLocaleUntranslatedStrings::iterator i = strings.find(str);
+ if ( i == strings.end() )
+ return *strings.insert(str).first;
return *i;
}
-const wxString& wxTranslations::GetString(const wxString& origString,
- const wxString& domain) const
+const wxString *wxTranslations::GetTranslatedString(const wxString& origString,
+ const wxString& domain) const
{
- return GetString(origString, origString, UINT_MAX, domain);
+ return GetTranslatedString(origString, UINT_MAX, domain);
}
-const wxString& wxTranslations::GetString(const wxString& origString,
- const wxString& origString2,
- unsigned n,
- const wxString& domain) const
+const wxString *wxTranslations::GetTranslatedString(const wxString& origString,
+ unsigned n,
+ const wxString& domain) const
{
if ( origString.empty() )
- return GetUntranslatedString(origString);
+ return NULL;
const wxString *trans = NULL;
wxMsgCatalog *pMsgCat;
(!domain.empty() ? wxString::Format("domain '%s' ", domain) : wxString()),
m_lang
);
-
- if (n == UINT_MAX)
- return GetUntranslatedString(origString);
- else
- return GetUntranslatedString(n == 1 ? origString : origString2);
}
- return *trans;
+ return trans;
}
wxString GetMsgCatalogSubdirs(const wxString& prefix, const wxString& lang)
{
// Search first in Unix-standard prefix/lang/LC_MESSAGES, then in
- // prefix/lang and finally in just prefix.
+ // prefix/lang.
//
// Note that we use LC_MESSAGES on all platforms and not just Unix, because
// it doesn't cost much to look into one more directory and doing it this
wxString searchPath;
searchPath.reserve(4*prefixAndLang.length());
- searchPath << prefixAndLang << wxFILE_SEP_PATH << "LC_MESSAGES" << wxPATH_SEP
+
+ searchPath
+#ifdef __WXOSX__
+ << prefixAndLang << ".lproj/LC_MESSAGES" << wxPATH_SEP
+ << prefixAndLang << ".lproj" << wxPATH_SEP
+#endif
+ << prefixAndLang << wxFILE_SEP_PATH << "LC_MESSAGES" << wxPATH_SEP
<< prefixAndLang << wxPATH_SEP
- << prefix;
+ ;
return searchPath;
}
// get prefixes to locale directories; if lang is empty, don't point to
// OSX's .lproj bundles
-wxArrayString GetSearchPrefixes(const wxString& lang = wxString())
+wxArrayString GetSearchPrefixes()
{
wxArrayString paths;
#if wxUSE_STDPATHS
// then look in the standard location
wxString stdp;
- if ( lang.empty() )
- {
- stdp = wxStandardPaths::Get().GetResourcesDir();
- }
- else
- {
- stdp = wxStandardPaths::Get().
- GetLocalizedResourcesDir(lang, wxStandardPaths::ResourceCat_Messages);
- }
+ stdp = wxStandardPaths::Get().GetResourcesDir();
if ( paths.Index(stdp) == wxNOT_FOUND )
paths.Add(stdp);
#endif // wxUSE_STDPATHS
wxString searchPath;
searchPath.reserve(500);
- const wxArrayString prefixes = GetSearchPrefixes(lang);
+ const wxArrayString prefixes = GetSearchPrefixes();
for ( wxArrayString::const_iterator i = prefixes.begin();
i != prefixes.end();