mobile-ios/CovidSafe/URLHelper.swift

50 lines
1.6 KiB
Swift
Raw 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"
2020-05-08 07:49:14 +00:00
static func getAustralianNumberURL() -> String {
2020-07-03 04:26:13 +00:00
return "\(getHelpURL())#verify-mobile-number-pin"
2020-05-08 07:49:14 +00:00
}
2020-08-18 00:52:17 +00:00
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
let matches = supportedLocales.filter { (supportedLocale) -> Bool in
return localeId.starts(with: supportedLocale)
2020-08-18 00:52:17 +00:00
|| 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
}
static func getHelpURL() -> String {
let localeCode = getLocale()
guard localeCode != "en" else {
return "\(host)/help-topics.html"
2020-07-03 04:26:13 +00:00
}
2020-08-18 00:52:17 +00:00
return "\(host)/help-topics/\(localeCode.lowercased()).html"
}
static func getPrivacyPolicyURL() -> String {
return "\(host)/privacy-policy.html"
2020-05-08 07:49:14 +00:00
}
}