mobile-ios/CovidSafe/String+Localization.swift

35 lines
997 B
Swift
Raw Permalink Normal View History

2020-06-19 07:43:33 +00:00
//
// String+Localization.swift
// CovidSafe
//
// Copyright © 2020 Australian Government. All rights reserved.
//
import Foundation
extension String {
func localizedString( comment: String = "") -> String {
if self == "" {
return ""
}
2020-07-21 05:42:48 +00:00
var localizedString = NSLocalizedString(self, comment: comment)
2021-02-02 00:04:43 +00:00
if localizedString == self || localizedString == "" {
2020-07-21 05:42:48 +00:00
// No localized string exists. Retrieve the display string
// from the base strings file.
var bundleForString: Bundle
if let path = Bundle.main.path(forResource: "en", ofType: "lproj"),
let bundle = Bundle(path: path) {
bundleForString = bundle
} else {
bundleForString = Bundle.main
}
localizedString = bundleForString.localizedString(forKey: self, value: self, table: nil)
}
return localizedString
2020-06-19 07:43:33 +00:00
}
}