Localize Pool via country code + area

This commit is contained in:
Davide De Rosa 2019-03-21 00:24:17 +01:00
parent 78a35b590c
commit 3eb9c6ae98
5 changed files with 323 additions and 1 deletions

View File

@ -77,7 +77,7 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
let cell = Cells.setting.dequeue(from: tableView, for: indexPath) let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = pool.name cell.leftText = pool.name
// cell.rightText = pool.country // cell.rightText = pool.area
cell.applyChecked(pool.id == currentPoolId, Theme.current) cell.applyChecked(pool.id == currentPoolId, Theme.current)
cell.isTappable = true cell.isTappable = true
return cell return cell

View File

@ -73,6 +73,7 @@
0E57F64620C83FC7008323CF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E57F64420C83FC7008323CF /* LaunchScreen.storyboard */; }; 0E57F64620C83FC7008323CF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0E57F64420C83FC7008323CF /* LaunchScreen.storyboard */; };
0E58BD9322404EF1006FB157 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BD9122404EF1006FB157 /* Intents.intentdefinition */; }; 0E58BD9322404EF1006FB157 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BD9122404EF1006FB157 /* Intents.intentdefinition */; };
0E58BF65224152F9006FB157 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BD9122404EF1006FB157 /* Intents.intentdefinition */; settings = {ATTRIBUTES = (no_codegen, ); }; }; 0E58BF65224152F9006FB157 /* Intents.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 0E58BD9122404EF1006FB157 /* Intents.intentdefinition */; settings = {ATTRIBUTES = (no_codegen, ); }; };
0E58BF68224305A8006FB157 /* Countries.strings in Resources */ = {isa = PBXBuildFile; fileRef = 0E58BF6A224305A8006FB157 /* Countries.strings */; };
0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */; }; 0E6BE13F20CFBAB300A6DD36 /* DebugLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E6BE13E20CFBAB300A6DD36 /* DebugLogViewController.swift */; };
0E89DFCE213EEDFA00741BA1 /* WizardProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */; }; 0E89DFCE213EEDFA00741BA1 /* WizardProviderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E89DFCD213EEDFA00741BA1 /* WizardProviderViewController.swift */; };
0EA068F4218475F800C320AD /* ParsingResult+Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA068F3218475F800C320AD /* ParsingResult+Alerts.swift */; }; 0EA068F4218475F800C320AD /* ParsingResult+Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EA068F3218475F800C320AD /* ParsingResult+Alerts.swift */; };
@ -195,6 +196,7 @@
0E57F64220C83FC7008323CF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 0E57F64220C83FC7008323CF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
0E57F64720C83FC7008323CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 0E57F64720C83FC7008323CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0E58BD9222404EF1006FB157 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = en; path = en.lproj/Intents.intentdefinition; sourceTree = "<group>"; }; 0E58BD9222404EF1006FB157 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; name = en; path = en.lproj/Intents.intentdefinition; sourceTree = "<group>"; };
0E58BF69224305A8006FB157 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Countries.strings; sourceTree = "<group>"; };
0E5E5DDE215119AF00E318A3 /* VPNStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNStatus.swift; sourceTree = "<group>"; }; 0E5E5DDE215119AF00E318A3 /* VPNStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNStatus.swift; sourceTree = "<group>"; };
0E5E5DE1215119DD00E318A3 /* VPNConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNConfiguration.swift; sourceTree = "<group>"; }; 0E5E5DE1215119DD00E318A3 /* VPNConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNConfiguration.swift; sourceTree = "<group>"; };
0E5E5DE421511C5F00E318A3 /* GracefulVPN.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GracefulVPN.swift; sourceTree = "<group>"; }; 0E5E5DE421511C5F00E318A3 /* GracefulVPN.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GracefulVPN.swift; sourceTree = "<group>"; };
@ -478,6 +480,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0E0EABC721DF853C0069DAE7 /* Web */, 0E0EABC721DF853C0069DAE7 /* Web */,
0E58BF6A224305A8006FB157 /* Countries.strings */,
0E05C5DF20D198B9006EE732 /* Localizable.strings */, 0E05C5DF20D198B9006EE732 /* Localizable.strings */,
); );
path = Resources; path = Resources;
@ -749,6 +752,7 @@
isa = PBXResourcesBuildPhase; isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
0E58BF68224305A8006FB157 /* Countries.strings in Resources */,
0E3152DD223FA06100F61841 /* Localizable.strings in Resources */, 0E3152DD223FA06100F61841 /* Localizable.strings in Resources */,
0E3152DE223FA06400F61841 /* Web in Resources */, 0E3152DE223FA06400F61841 /* Web in Resources */,
); );
@ -1096,6 +1100,14 @@
name = Intents.intentdefinition; name = Intents.intentdefinition;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
0E58BF6A224305A8006FB157 /* Countries.strings */ = {
isa = PBXVariantGroup;
children = (
0E58BF69224305A8006FB157 /* en */,
);
name = Countries.strings;
sourceTree = "<group>";
};
0ED38ADC213F44D00004D387 /* Organizer.storyboard */ = { 0ED38ADC213F44D00004D387 /* Organizer.storyboard */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (

View File

@ -0,0 +1,275 @@
//
// Countries.strings
// Passepartout
//
// Created by Davide De Rosa on 3/21/19.
// Copyright (c) 2019 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Passepartout is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
"BD" = "Bangladesh";
"BE" = "Belgium";
"BF" = "Burkina Faso";
"BG" = "Bulgaria";
"BA" = "Bosnia and Herzegovina";
"BB" = "Barbados";
"WF" = "Wallis and Futuna";
"BL" = "Saint Barthelemy";
"BM" = "Bermuda";
"BN" = "Brunei";
"BO" = "Bolivia";
"BH" = "Bahrain";
"BI" = "Burundi";
"BJ" = "Benin";
"BT" = "Bhutan";
"JM" = "Jamaica";
"BV" = "Bouvet Island";
"BW" = "Botswana";
"WS" = "Samoa";
"BQ" = "Bonaire, Saint Eustatius and Saba ";
"BR" = "Brazil";
"BS" = "Bahamas";
"JE" = "Jersey";
"BY" = "Belarus";
"BZ" = "Belize";
"RU" = "Russia";
"RW" = "Rwanda";
"RS" = "Serbia";
"TL" = "East Timor";
"RE" = "Reunion";
"TM" = "Turkmenistan";
"TJ" = "Tajikistan";
"RO" = "Romania";
"TK" = "Tokelau";
"GW" = "Guinea-Bissau";
"GU" = "Guam";
"GT" = "Guatemala";
"GS" = "South Georgia and the South Sandwich Islands";
"GR" = "Greece";
"GQ" = "Equatorial Guinea";
"GP" = "Guadeloupe";
"JP" = "Japan";
"GY" = "Guyana";
"GG" = "Guernsey";
"GF" = "French Guiana";
"GE" = "Georgia";
"GD" = "Grenada";
"GB" = "United Kingdom";
"GA" = "Gabon";
"SV" = "El Salvador";
"GN" = "Guinea";
"GM" = "Gambia";
"GL" = "Greenland";
"GI" = "Gibraltar";
"GH" = "Ghana";
"OM" = "Oman";
"TN" = "Tunisia";
"JO" = "Jordan";
"HR" = "Croatia";
"HT" = "Haiti";
"HU" = "Hungary";
"HK" = "Hong Kong";
"HN" = "Honduras";
"HM" = "Heard Island and McDonald Islands";
"VE" = "Venezuela";
"PR" = "Puerto Rico";
"PS" = "Palestinian Territory";
"PW" = "Palau";
"PT" = "Portugal";
"SJ" = "Svalbard and Jan Mayen";
"PY" = "Paraguay";
"IQ" = "Iraq";
"PA" = "Panama";
"PF" = "French Polynesia";
"PG" = "Papua New Guinea";
"PE" = "Peru";
"PK" = "Pakistan";
"PH" = "Philippines";
"PN" = "Pitcairn";
"PL" = "Poland";
"PM" = "Saint Pierre and Miquelon";
"ZM" = "Zambia";
"EH" = "Western Sahara";
"EE" = "Estonia";
"EG" = "Egypt";
"ZA" = "South Africa";
"EC" = "Ecuador";
"IT" = "Italy";
"VN" = "Vietnam";
"SB" = "Solomon Islands";
"ET" = "Ethiopia";
"SO" = "Somalia";
"ZW" = "Zimbabwe";
"SA" = "Saudi Arabia";
"ES" = "Spain";
"ER" = "Eritrea";
"ME" = "Montenegro";
"MD" = "Moldova";
"MG" = "Madagascar";
"MF" = "Saint Martin";
"MA" = "Morocco";
"MC" = "Monaco";
"UZ" = "Uzbekistan";
"MM" = "Myanmar";
"ML" = "Mali";
"MO" = "Macao";
"MN" = "Mongolia";
"MH" = "Marshall Islands";
"MK" = "Macedonia";
"MU" = "Mauritius";
"MT" = "Malta";
"MW" = "Malawi";
"MV" = "Maldives";
"MQ" = "Martinique";
"MP" = "Northern Mariana Islands";
"MS" = "Montserrat";
"MR" = "Mauritania";
"IM" = "Isle of Man";
"UG" = "Uganda";
"TZ" = "Tanzania";
"MY" = "Malaysia";
"MX" = "Mexico";
"IL" = "Israel";
"FR" = "France";
"IO" = "British Indian Ocean Territory";
"SH" = "Saint Helena";
"FI" = "Finland";
"FJ" = "Fiji";
"FK" = "Falkland Islands";
"FM" = "Micronesia";
"FO" = "Faroe Islands";
"NI" = "Nicaragua";
"NL" = "Netherlands";
"NO" = "Norway";
"NA" = "Namibia";
"VU" = "Vanuatu";
"NC" = "New Caledonia";
"NE" = "Niger";
"NF" = "Norfolk Island";
"NG" = "Nigeria";
"NZ" = "New Zealand";
"NP" = "Nepal";
"NR" = "Nauru";
"NU" = "Niue";
"CK" = "Cook Islands";
"XK" = "Kosovo";
"CI" = "Ivory Coast";
"CH" = "Switzerland";
"CO" = "Colombia";
"CN" = "China";
"CM" = "Cameroon";
"CL" = "Chile";
"CC" = "Cocos Islands";
"CA" = "Canada";
"CG" = "Republic of the Congo";
"CF" = "Central African Republic";
"CD" = "Democratic Republic of the Congo";
"CZ" = "Czech Republic";
"CY" = "Cyprus";
"CX" = "Christmas Island";
"CR" = "Costa Rica";
"CW" = "Curacao";
"CV" = "Cape Verde";
"CU" = "Cuba";
"SZ" = "Swaziland";
"SY" = "Syria";
"SX" = "Sint Maarten";
"KG" = "Kyrgyzstan";
"KE" = "Kenya";
"SS" = "South Sudan";
"SR" = "Suriname";
"KI" = "Kiribati";
"KH" = "Cambodia";
"KN" = "Saint Kitts and Nevis";
"KM" = "Comoros";
"ST" = "Sao Tome and Principe";
"SK" = "Slovakia";
"KR" = "South Korea";
"SI" = "Slovenia";
"KP" = "North Korea";
"KW" = "Kuwait";
"SN" = "Senegal";
"SM" = "San Marino";
"SL" = "Sierra Leone";
"SC" = "Seychelles";
"KZ" = "Kazakhstan";
"KY" = "Cayman Islands";
"SG" = "Singapore";
"SE" = "Sweden";
"SD" = "Sudan";
"DO" = "Dominican Republic";
"DM" = "Dominica";
"DJ" = "Djibouti";
"DK" = "Denmark";
"VG" = "British Virgin Islands";
"DE" = "Germany";
"YE" = "Yemen";
"DZ" = "Algeria";
"US" = "United States";
"UY" = "Uruguay";
"YT" = "Mayotte";
"UM" = "United States Minor Outlying Islands";
"LB" = "Lebanon";
"LC" = "Saint Lucia";
"LA" = "Laos";
"TV" = "Tuvalu";
"TW" = "Taiwan";
"TT" = "Trinidad and Tobago";
"TR" = "Turkey";
"LK" = "Sri Lanka";
"LI" = "Liechtenstein";
"LV" = "Latvia";
"TO" = "Tonga";
"LT" = "Lithuania";
"LU" = "Luxembourg";
"LR" = "Liberia";
"LS" = "Lesotho";
"TH" = "Thailand";
"TF" = "French Southern Territories";
"TG" = "Togo";
"TD" = "Chad";
"TC" = "Turks and Caicos Islands";
"LY" = "Libya";
"VA" = "Vatican";
"VC" = "Saint Vincent and the Grenadines";
"AE" = "United Arab Emirates";
"AD" = "Andorra";
"AG" = "Antigua and Barbuda";
"AF" = "Afghanistan";
"AI" = "Anguilla";
"VI" = "U.S. Virgin Islands";
"IS" = "Iceland";
"IR" = "Iran";
"AM" = "Armenia";
"AL" = "Albania";
"AO" = "Angola";
"AQ" = "Antarctica";
"AS" = "American Samoa";
"AR" = "Argentina";
"AU" = "Australia";
"AT" = "Austria";
"AW" = "Aruba";
"IN" = "India";
"AX" = "Aland Islands";
"AZ" = "Azerbaijan";
"IE" = "Ireland";
"ID" = "Indonesia";
"UA" = "Ukraine";
"QA" = "Qatar";
"MZ" = "Mozambique";

View File

@ -34,6 +34,8 @@ public struct Pool: Codable, Comparable, CustomStringConvertible {
case country case country
case area
// case location // case location
case hostname case hostname
@ -47,6 +49,8 @@ public struct Pool: Codable, Comparable, CustomStringConvertible {
public let country: String public let country: String
public let area: String?
// public let location: (Double, Double) // public let location: (Double, Double)
public let hostname: String public let hostname: String
@ -70,6 +74,15 @@ public struct Pool: Codable, Comparable, CustomStringConvertible {
// MARK: Comparable // MARK: Comparable
public static func <(lhs: Pool, rhs: Pool) -> Bool { public static func <(lhs: Pool, rhs: Pool) -> Bool {
if lhs.name == rhs.name {
guard let larea = lhs.area else {
return true
}
guard let rarea = rhs.area else {
return false
}
return larea < rarea
}
return lhs.name < rhs.name return lhs.name < rhs.name
} }
@ -79,3 +92,20 @@ public struct Pool: Codable, Comparable, CustomStringConvertible {
return "{[\(id)] \"\(name)\"}" return "{[\(id)] \"\(name)\"}"
} }
} }
extension Pool {
private static let localizedFormat = "%@ - %@"
public var localizedCountry: String {
return Utils.localizedCountry(country)
}
public var name: String {
let countryString = localizedCountry
guard let area = area else {
return countryString
}
return String.init(format: Pool.localizedFormat, countryString, area.uppercased())
// return countryString
}
}

View File

@ -133,6 +133,11 @@ public class Utils {
}.resume() }.resume()
} }
public static func localizedCountry(_ code: String) -> String {
let format = NSLocalizedString(code.uppercased(), tableName: "Countries", bundle: Bundle(for: Utils.self), comment: "")
return String(format: format, locale: Locale.current)
}
private init() { private init() {
} }
} }