mobile-ios/CovidSafe/URLHelper.swift

70 lines
2.3 KiB
Swift
Raw Permalink Normal View History

2020-05-08 07:49:14 +00:00
//
// URLHelper.swift
// CovidSafe
//
// Copyright © 2020 Australian Government. All rights reserved.
//
import Foundation
struct URLHelper {
2020-08-18 00:52:17 +00:00
static let host = "https://www.covidsafe.gov.au"
private static func getLocale() -> String {
guard let langCode = Locale.current.languageCode else {
return "en"
}
2020-07-03 04:26:13 +00:00
let localeId = Locale.current.identifier
let supportedLocales = Bundle.main.localizations
2020-09-14 01:23:11 +00:00
var matches = supportedLocales.filter { (supportedLocale) -> Bool in
2020-07-03 04:26:13 +00:00
return localeId.starts(with: supportedLocale)
2020-09-14 01:23:11 +00:00
}
if matches.count == 0 {
matches = supportedLocales.filter { (supportedLocale) -> Bool in
return supportedLocale.starts(with: "\(langCode)-") // for punjabi is particularly special that the identifier is pa_AU although
// the language code in the supported locals is pa-IN.
// just checking it has the pa- should be enough. I anticipate this happening in other dialects as they come.
}
2020-07-03 04:26:13 +00:00
}
2020-08-18 00:52:17 +00:00
guard let localeCode = matches.first else {
return "en"
}
return localeCode
}
2020-09-14 01:23:11 +00:00
static fileprivate func buildLocalisedURL(path: String) -> String {
2020-08-18 00:52:17 +00:00
let localeCode = getLocale()
guard localeCode != "en" else {
2020-09-14 01:23:11 +00:00
return "\(host)/\(path).html"
2020-07-03 04:26:13 +00:00
}
2020-09-14 01:23:11 +00:00
return "\(host)/\(path)/\(localeCode.lowercased()).html"
}
static func getHelpURL() -> String {
return buildLocalisedURL(path: "help-topics")
2020-08-18 00:52:17 +00:00
}
static func getPrivacyPolicyURL() -> String {
2020-09-14 01:23:11 +00:00
return buildLocalisedURL(path: "privacy-policy")
}
2021-02-02 00:04:43 +00:00
static func getCollectionNoticeURL() -> String {
// "https://covidsafe.gov.au/collection-notice.html"
return buildLocalisedURL(path: "collection-notice")
}
2020-09-14 01:23:11 +00:00
static func getAustralianNumberURL() -> String {
return "\(getHelpURL())#verify-mobile-number-pin"
2020-05-08 07:49:14 +00:00
}
2021-02-02 00:04:43 +00:00
static func geLocationPermissionsURL() -> String {
return "\(getHelpURL())#location-permissions"
}
2021-05-13 00:39:38 +00:00
static func getDataDeletionURL() -> String {
return "https://covidsafe-form.service.gov.au"
}
2020-05-08 07:49:14 +00:00
}