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