mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-10-23 03:26:59 +09:00
feat: server country code l10n (#3069)
This commit is contained in:
10 files changed
+23
-7
No files matched your search
@@ -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();
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ struct ApiConfig
|
||||
QString serviceProtocol;
|
||||
QString userCountryCode;
|
||||
QString serverCountryCode;
|
||||
QString serverCountryCodeL10n;
|
||||
QString serverCountryName;
|
||||
QString vpnKey;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -40,6 +40,7 @@ struct ServerDescription
|
||||
bool isCountrySelectionAvailable = false;
|
||||
QJsonArray apiAvailableCountries;
|
||||
QString apiServerCountryCode;
|
||||
QString apiServerCountryCodeL10n;
|
||||
|
||||
bool isAdVisible = false;
|
||||
QString adHeader;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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 "";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
{
|
||||
QString countryName;
|
||||
QString countryCode;
|
||||
QString countryCodeL10n;
|
||||
};
|
||||
|
||||
QVector<CountryInfo> m_countries;
|
||||
|
||||
Reference in new issue
Block a user