feat: server country code l10n (#3069)

This commit is contained in:
yp authored and GitHub committed 2026-08-28 23:10:41 +08:00
1 parent 5689706fd9
commit dddc181299
10 files changed
+23 -7

No files matched your search

+4
View File
@@ -118,6 +118,9 @@ QJsonObject ApiConfig::toJson() const
if (!serverCountryCode.isEmpty()) {
obj[apiDefs::key::serverCountryCode] = serverCountryCode;
}
if (!serverCountryCodeL10n.isEmpty()) {
obj[apiDefs::key::serverCountryCodeL10n] = serverCountryCodeL10n;
}
if (!serverCountryName.isEmpty()) {
obj[apiDefs::key::serverCountryName] = serverCountryName;
}
@@ -181,6 +184,7 @@ ApiConfig ApiConfig::fromJson(const QJsonObject& json)
config.serviceProtocol = json.value(QLatin1String("service_protocol")).toString();
config.userCountryCode = json.value(QLatin1String("user_country_code")).toString();
config.serverCountryCode = json.value(apiDefs::key::serverCountryCode).toString();
config.serverCountryCodeL10n = json.value(apiDefs::key::serverCountryCodeL10n).toString();
config.serverCountryName = json.value(apiDefs::key::serverCountryName).toString();
config.vpnKey = json.value(apiDefs::key::vpnKey).toString();
+1
View File
@@ -19,6 +19,7 @@ struct ApiConfig
QString serviceProtocol;
QString userCountryCode;
QString serverCountryCode;
QString serverCountryCodeL10n;
QString serverCountryName;
QString vpnKey;
+1
View File
@@ -166,6 +166,7 @@ ServerDescription buildServerDescription(const ApiV2ServerConfig &server, bool /
row.isCountrySelectionAvailable = !server.apiConfig.availableCountries.isEmpty();
row.apiAvailableCountries = server.apiConfig.availableCountries;
row.apiServerCountryCode = server.apiConfig.serverCountryCode;
row.apiServerCountryCodeL10n = server.apiConfig.serverCountryCodeL10n;
row.isAdVisible = server.apiConfig.serviceInfo.isAdVisible;
row.adHeader = server.apiConfig.serviceInfo.adHeader;
+1
View File
@@ -40,6 +40,7 @@ struct ServerDescription
bool isCountrySelectionAvailable = false;
QJsonArray apiAvailableCountries;
QString apiServerCountryCode;
QString apiServerCountryCodeL10n;
bool isAdVisible = false;
QString adHeader;
+7 -1
View File
@@ -72,8 +72,14 @@ QString apiUtils::getDistributionChannel()
#endif
}
QString apiUtils::getCountryFlagCode(const QString &serverCountryCode)
QString apiUtils::getCountryFlagCode(const QString &serverCountryCodeL10n, const QString &serverCountryCode)
{
if (!serverCountryCodeL10n.isEmpty()) {
return serverCountryCodeL10n.toUpper();
}
if (serverCountryCode.isEmpty()) {
return {};
}
return serverCountryCode.section('-', 0, 0).toUpper();
}
+4 -4
View File
@@ -18,10 +18,10 @@ namespace apiUtils
QString getAppLanguageCode(const SecureAppSettingsRepository *appSettingsRepository);
QString getDistributionChannel();
// The gateway may report a country code with a region suffix, e.g. "us-west", while flag
// resources are named after the ISO 3166-1 alpha-2 code alone. Returns the part before the dash
// in upper case.
QString getCountryFlagCode(const QString &serverCountryCode);
// Flag lookup: prefer serverCountryCodeL10n (ISO code from Stack); fall back to serverCountryCode
// for old stacks. Routing code may contain region/pool suffixes — strip at most one dash segment
// on fallback only. Returns upper-case ISO 3166-1 alpha-2 when possible.
QString getCountryFlagCode(const QString &serverCountryCodeL10n, const QString &serverCountryCode);
bool isSubscriptionExpired(const QString &subscriptionEndDate);
+1
View File
@@ -26,6 +26,7 @@ namespace apiDefs
constexpr QLatin1String distribution("distribution");
constexpr QLatin1String userCountryCode("user_country_code");
constexpr QLatin1String serverCountryCode("server_country_code");
constexpr QLatin1String serverCountryCodeL10n("server_country_code_l10n");
constexpr QLatin1String serverCountryName("server_country_name");
constexpr QLatin1String appVersion("app_version");
constexpr QLatin1String authData("auth_data");
@@ -209,7 +209,7 @@ QString ServersUiController::getDefaultServerImagePathCollapsed() const
if (!description.isApiV2) {
return "";
}
const QString flagCode = apiUtils::getCountryFlagCode(description.apiServerCountryCode);
const QString flagCode = apiUtils::getCountryFlagCode(description.apiServerCountryCodeL10n, description.apiServerCountryCode);
if (flagCode.isEmpty()) {
return "";
}
+2 -1
View File
@@ -42,7 +42,7 @@ QVariant ApiCountryModel::data(const QModelIndex &index, int role) const
return countryInfo.countryName;
}
case CountryImageCodeRole: {
return apiUtils::getCountryFlagCode(countryInfo.countryCode);
return apiUtils::getCountryFlagCode(countryInfo.countryCodeL10n, countryInfo.countryCode);
}
case IsIssuedRole: {
return isIssued;
@@ -66,6 +66,7 @@ void ApiCountryModel::updateModel(const QJsonArray &countries, const QString &cu
countryInfo.countryName = countryObject.value(apiDefs::key::serverCountryName).toString();
countryInfo.countryCode = countryObject.value(apiDefs::key::serverCountryCode).toString();
countryInfo.countryCodeL10n = countryObject.value(apiDefs::key::serverCountryCodeL10n).toString();
if (countryInfo.countryCode == currentCountryCode) {
m_currentIndex = i;
+1
View File
@@ -53,6 +53,7 @@ private:
{
QString countryName;
QString countryCode;
QString countryCodeL10n;
};
QVector<CountryInfo> m_countries;