Skip to content

Commit

Permalink
feat: override icu database
Browse files Browse the repository at this point in the history
Taiwan -> Taiwan China

pms: BUG-368711
  • Loading branch information
mhduiy committed Jan 15, 2025
1 parent baaebbf commit 0587066
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions src/plugin-datetime/operation/datetimemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@

static installer::ZoneInfoList g_totalZones;

static QString GetChinaTaiWanName()
{
switch (QLocale::system().territory()) {
case QLocale::Territory::China:
return QStringLiteral("中国台湾");
case QLocale::Territory::HongKong:
return QStringLiteral("中國台灣");
case QLocale::Territory::Taiwan:
return QStringLiteral("中國臺灣");
case QLocale::Territory::Macau:
return QStringLiteral("中國台灣");
default:
return "Taiwan China";
}
}

static const QMap<QString, QMap<QLocale::Language, QString>> localeOverrides = {
{"zh_TW", {
{QLocale::Chinese, GetChinaTaiWanName()},
{QLocale::English, "Taiwan China"},
}},
{"trv_TW", {
{QLocale::Chinese, GetChinaTaiWanName()},
{QLocale::English, "Taiwan China"}
}},
};

static QString getDescription(const ZoneInfo &zoneInfo)
{
const QDateTime localTime(QDateTime::currentDateTime());
Expand Down Expand Up @@ -150,6 +177,13 @@ static QStringList translateLangAndCountry(const QString &localeName)
std::string displayCountryIcu;
IcuLocale.getDisplayCountry(systemLocale, localeHex).toUTF8String(displayCountryIcu);

// override icu, e.g. 台湾 -> 中国台湾
if (localeOverrides.contains(localeName)) {
if (localeOverrides[localeName].contains(QLocale::system().language())) {
displayCountryIcu = localeOverrides[localeName][QLocale::system().language()].toStdString();
}
}

return QStringList{ QString::fromStdString(displayLanguageIcu),
QString::fromStdString(displayCountryIcu) };
}
Expand All @@ -166,12 +200,16 @@ static QString translate(const QString &localeName, const QString &langRegion)
|| langRegions[1] == QLocale::countryToString(QLocale::Macau)
|| langRegions[1] == QLocale::countryToString(QLocale::Taiwan)) {

QString langCountry =
QString("%1(%2)")
.arg(QCoreApplication::translate("dcc::datetime::Language",
langRegions.at(0).toUtf8().data()))
.arg(QCoreApplication::translate("dcc::datetime::Country",
langRegions.at(1).toUtf8().data()));
auto res = translateLangAndCountry(localeName);
QString lang = res.value(0);

// override icu, e.g. 台湾 -> 中国台湾
QString country = langRegions.at(1).toUtf8().data();
if (country == "Taiwan") {
country = GetChinaTaiWanName();
}

QString langCountry = QString("%1(%2)").arg(lang).arg(country);
return langCountry;
}

Expand Down

0 comments on commit 0587066

Please sign in to comment.