multiple intricate implementations
This commit is contained in:
1 parent
7aa4ea4425
commit
77690cbd96
109 files changed
+2045
-56
No files matched your search
+79
-5
@@ -32,6 +32,10 @@
|
||||
#include "Cevo/CevoScreenTools.h"
|
||||
#include "Cevo/CevoTexture.h"
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QLocale>
|
||||
#include <QStandardPaths>
|
||||
|
||||
namespace Cevo {
|
||||
|
||||
@@ -67,12 +71,62 @@ QString getMusicDir()
|
||||
return dir.isEmpty() ? QString() : dir + QStringLiteral("/Music");
|
||||
}
|
||||
|
||||
QString localizedFilePath(const QString &path)
|
||||
QString getAppSharePath(const QString &path)
|
||||
{
|
||||
const QString dir = resourceDir();
|
||||
return dir.isEmpty() ? path : dir + QLatin1Char('/') + path;
|
||||
}
|
||||
|
||||
QString localeCode;
|
||||
|
||||
QString localeCodeAuto()
|
||||
{
|
||||
const QLocale locale = QLocale::system();
|
||||
if (locale.language() == QLocale::Chinese) {
|
||||
return locale.script() == QLocale::TraditionalChineseScript ? QStringLiteral("zh-Hant")
|
||||
: QStringLiteral("zh-Hans");
|
||||
}
|
||||
return locale.name().section(QLatin1Char('_'), 0, 0);
|
||||
}
|
||||
|
||||
QString localizedFilePath(const QString &path)
|
||||
{
|
||||
if (localeCode != QLatin1String("en")) {
|
||||
const QString code = localeCode.isEmpty() ? localeCodeAuto() : localeCode;
|
||||
const QString localized = getAppSharePath(QStringLiteral("Localization/") + code + QLatin1Char('/') + path);
|
||||
if (QFileInfo::exists(localized))
|
||||
return localized;
|
||||
}
|
||||
return getAppSharePath(path);
|
||||
}
|
||||
|
||||
namespace {
|
||||
QString dataDirectory;
|
||||
}
|
||||
|
||||
void initDirectories(const QStringList &args)
|
||||
{
|
||||
dataDirectory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
if (dataDirectory.isEmpty())
|
||||
dataDirectory = getAppSharePath(QString());
|
||||
// Override by parameter
|
||||
for (int i = 1; i < args.size() - 1; ++i) {
|
||||
if (args.at(i) == QLatin1String("-d") || args.at(i) == QLatin1String("--data-dir"))
|
||||
dataDirectory = args.at(i + 1);
|
||||
}
|
||||
QDir().mkpath(dataDirectory);
|
||||
}
|
||||
|
||||
QString getSavedDir(bool share)
|
||||
{
|
||||
return share ? getAppSharePath(QStringLiteral("Saved")) : dataDirectory + QStringLiteral("/Saved");
|
||||
}
|
||||
|
||||
QString getMapsDir(bool share)
|
||||
{
|
||||
return share ? getAppSharePath(QStringLiteral("Maps")) : dataDirectory + QStringLiteral("/Maps");
|
||||
}
|
||||
|
||||
StringTable phrases;
|
||||
StringTable phrases2;
|
||||
bool phrases2FallenBackToEnglish = false;
|
||||
@@ -80,10 +134,30 @@ bool phrases2FallenBackToEnglish = false;
|
||||
void loadPhrases()
|
||||
{
|
||||
phrases2FallenBackToEnglish = false;
|
||||
if (!phrases.loadFromFile(localizedFilePath(QStringLiteral("Language.txt"))))
|
||||
qWarning("Language.txt not found in %s", qPrintable(localizedFilePath(QString())));
|
||||
if (!phrases2.loadFromFile(localizedFilePath(QStringLiteral("Language2.txt"))))
|
||||
qWarning("Language2.txt not found in %s", qPrintable(localizedFilePath(QString())));
|
||||
const QString languageFile = localizedFilePath(QStringLiteral("Language.txt"));
|
||||
if (QFileInfo::exists(languageFile)) {
|
||||
phrases.loadFromFile(languageFile);
|
||||
const QString language2File = localizedFilePath(QStringLiteral("Language2.txt"));
|
||||
if (QFileInfo::exists(language2File)) {
|
||||
phrases2.loadFromFile(language2File);
|
||||
} else {
|
||||
phrases2.loadFromFile(getAppSharePath(QStringLiteral("Language2.txt")));
|
||||
phrases2FallenBackToEnglish = true;
|
||||
}
|
||||
} else {
|
||||
phrases.loadFromFile(getAppSharePath(QStringLiteral("Language.txt")));
|
||||
phrases2.loadFromFile(getAppSharePath(QStringLiteral("Language2.txt")));
|
||||
}
|
||||
if (phrases.getHandle(QStringLiteral("BTN_OK")) < 0)
|
||||
qWarning("Language.txt not found in %s", qPrintable(getAppSharePath(QString())));
|
||||
}
|
||||
|
||||
QString formatPhrase(const QString &key, const QStringList &args)
|
||||
{
|
||||
QString result = phraseToQtFormat(phrases.lookup(key));
|
||||
for (const QString &arg : args)
|
||||
result = result.arg(arg);
|
||||
return result;
|
||||
}
|
||||
|
||||
void loadAssets()
|
||||
|
||||
Reference in new issue
Block a user