COVIDSafe code from version 1.11 (#22)

This commit is contained in:
COVIDSafe Support 2020-09-14 11:23:11 +10:00 committed by GitHub
parent 746841a945
commit a2b6a8bfb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 6555 additions and 2216 deletions

View file

@ -11,21 +11,21 @@ struct URLHelper {
static let host = "https://www.covidsafe.gov.au"
static func getAustralianNumberURL() -> String {
return "\(getHelpURL())#verify-mobile-number-pin"
}
private static func getLocale() -> String {
guard let langCode = Locale.current.languageCode else {
return "en"
}
let localeId = Locale.current.identifier
let supportedLocales = Bundle.main.localizations
let matches = supportedLocales.filter { (supportedLocale) -> Bool in
var matches = supportedLocales.filter { (supportedLocale) -> Bool in
return localeId.starts(with: supportedLocale)
|| 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.
}
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.
}
}
guard let localeCode = matches.first else {
return "en"
@ -33,17 +33,24 @@ struct URLHelper {
return localeCode
}
static func getHelpURL() -> String {
static fileprivate func buildLocalisedURL(path: String) -> String {
let localeCode = getLocale()
guard localeCode != "en" else {
return "\(host)/help-topics.html"
return "\(host)/\(path).html"
}
return "\(host)/help-topics/\(localeCode.lowercased()).html"
return "\(host)/\(path)/\(localeCode.lowercased()).html"
}
static func getHelpURL() -> String {
return buildLocalisedURL(path: "help-topics")
}
static func getPrivacyPolicyURL() -> String {
return "\(host)/privacy-policy.html"
return buildLocalisedURL(path: "privacy-policy")
}
static func getAustralianNumberURL() -> String {
return "\(getHelpURL())#verify-mobile-number-pin"
}
}