Look for translation .mo files in the new location

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/46/head
Michele Calgaro 1 week ago
parent bc34bb6c34
commit caab44d2c4
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -859,7 +859,8 @@ namespace KviLocale
TQString szBuffer;
if(findCatalogue(szBuffer,name,szLocaleDir))
TQString catalog_name = TQString("kvirc-" + name);
if(findCatalogue(szBuffer,catalog_name,szLocaleDir))
{
KviMessageCatalogue * c = new KviMessageCatalogue();
if(c->load(szBuffer))
@ -885,7 +886,7 @@ namespace KviLocale
TQString szLocDir = szLocaleDir;
KviTQString::ensureLastCharIs(szLocDir,KVI_PATH_SEPARATOR_CHAR);
KviTQString::sprintf(szBuffer,"%Q%Q_%s.mo",&szLocDir,&name,szLocale.ptr());
KviTQString::sprintf(szBuffer,"%Q%s/LC_MESSAGES/%Q.mo",&szLocDir,szLocale.ptr(),&name);
if(KviFileUtils::fileExists(szBuffer))return true;
@ -895,7 +896,7 @@ namespace KviLocale
// kill them
szLocale.cutFromFirst('.');
KviTQString::sprintf(szBuffer,"%Q%Q_%s.mo",&szLocDir,&name,szLocale.ptr());
KviTQString::sprintf(szBuffer,"%Q%s/LC_MESSAGES/%Q.mo",&szLocDir,szLocale.ptr(),&name);
if(KviFileUtils::fileExists(szBuffer))return true;
}
@ -904,7 +905,7 @@ namespace KviLocale
// things like @euro ?
// kill them
szLocale.cutFromFirst('@');
KviTQString::sprintf(szBuffer,"%Q%Q_%s.mo",&szLocDir,&name,szLocale.ptr());
KviTQString::sprintf(szBuffer,"%Q%s/LC_MESSAGES/%Q.mo",&szLocDir,szLocale.ptr(),&name);
if(KviFileUtils::fileExists(szBuffer))return true;
}
@ -913,13 +914,13 @@ namespace KviLocale
// things like en_GB
// kill them
szLocale.cutFromFirst('_');
KviTQString::sprintf(szBuffer,"%Q%Q_%s.mo",&szLocDir,&name,szLocale.ptr());
KviTQString::sprintf(szBuffer,"%Q%s/LC_MESSAGES/%Q.mo",&szLocDir,szLocale.ptr(),&name);
if(KviFileUtils::fileExists(szBuffer))return true;
}
// try the lower case version too
szLocale.toLower();
KviTQString::sprintf(szBuffer,"%Q%Q_%s.mo",&szLocDir,&name,szLocale.ptr());
KviTQString::sprintf(szBuffer,"%Q%s/LC_MESSAGES/%Q.mo",&szLocDir,szLocale.ptr(),&name);
if(KviFileUtils::fileExists(szBuffer))return true;
return false;
@ -928,11 +929,11 @@ namespace KviLocale
//
// This function attempts to determine the current locale
// and then load the corresponding translation file
// from the KVIrc locale directory
// from the system locale directory
// Returns true if the locale was correctly set
// i.e. the locale is C or POSIX (no translation needed)
// or the locale is correctly defined and the
// translation map was sucesfully loaded
// translation map was successfully loaded
//
void init(TQApplication * app,const TQString &localeDir)
@ -953,7 +954,6 @@ namespace KviLocale
if(g_szLang.isEmpty())g_szLang = "en";
g_szLang.stripWhiteSpace();
// the main catalogue is supposed to be kvirc_<language>.mo
g_pMainCatalogue = new KviMessageCatalogue();
// the catalogue dict
g_pCatalogueDict = new KviPointerHashTable<const char *,KviMessageCatalogue>;

@ -38,6 +38,7 @@
#include <tqdir.h>
#include <tqfileinfo.h>
#include <tqdatetime.h>
#include <tdestandarddirs.h>
#include "config.h"
@ -90,7 +91,7 @@ void KviApp::getGlobalKvircDirectory(TQString &szData,KvircSubdir dir,const TQSt
case DefScript : szData.append("defscript"); break;
case License : szData.append("license"); break;
case Filters : szData.append("filters"); break;
case Locale : szData.append("locale"); break;
case Locale : szData=locate("locale",""); break;
case Tmp : tqDebug("WARNING Global tmp directory requested!"); break;
case Themes : szData.append("themes"); break;
case Classes : szData.append("classes"); break;

@ -707,11 +707,7 @@ void KviApp::loadDirectories()
// First find the global (readable) one...
findGlobalKvircDirectory();
// Init locale
TQString szLocalePath = m_szGlobalKvircDir;
szLocalePath.append(KVI_PATH_SEPARATOR);
szLocalePath.append("locale");
szLocalePath.append(KVI_PATH_SEPARATOR);
TQString szLocalePath = locate("locale","");
KviLocale::init(this,szLocalePath);
//__debug_1arg("Global Kvirc directory is %s",m_szGlobalKvircDir.ptr());

@ -30,6 +30,10 @@
#include <tqdir.h>
#include <tqmessagebox.h>
#include <algorithm>
#include <filesystem>
#include <vector>
TQString g_szPrevSettedLocale;
KviTextEncodingOptionsWidget::KviTextEncodingOptionsWidget(TQWidget * parent)
@ -82,15 +86,29 @@ KviTextEncodingOptionsWidget::KviTextEncodingOptionsWidget(TQWidget * parent)
TQString szLocaleDir;
g_pApp->getGlobalKvircDirectory(szLocaleDir,KviApp::Locale);
TQStringList list=TQDir(szLocaleDir).entryList("kvirc_*.mo",TQDir::Files);
// Find available translations by checking for existance of kvirc.mo files
namespace fs = std::filesystem;
std::vector<fs::path> translationPaths;
const fs::path localeDir { szLocaleDir.local8Bit().data() };
for (const auto &dir : fs::directory_iterator(localeDir))
{
if (!dir.is_directory())
{
continue;
}
if (fs::exists(dir.path()/"LC_MESSAGES/kvirc.mo"))
{
translationPaths.push_back(dir.path().filename());
}
}
std::sort(translationPaths.begin(), translationPaths.end());
i = 0;
iMatch = 0;
for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
TQString szTmp=*it;
szTmp.replace("kvirc_","");
szTmp.replace(".mo","");
for (const auto &filename : translationPaths)
{
TQString szTmp { filename.c_str() };
m_pForcedLocaleCombo->insertItem(szTmp);
if(KviTQString::equalCI(szTmp,m_szLanguage))
iMatch = i + 2;

Loading…
Cancel
Save