Update localization documentation
This commit is contained in:
parent
f373cce6c7
commit
c046f62bcd
|
@ -19,6 +19,9 @@ public class BundleTranslator: Translator {
|
|||
|
||||
private let bundle: Bundle
|
||||
|
||||
/**
|
||||
Translate the provided key to a localized string.
|
||||
*/
|
||||
public func translate(_ key: String) -> String {
|
||||
bundle.localizedString(forKey: key, value: "", table: nil)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ import Foundation
|
|||
notifications when the app locale changes.
|
||||
*/
|
||||
public protocol LocalizationService: Translator {
|
||||
|
||||
|
||||
/**
|
||||
Change the service's locale.
|
||||
*/
|
||||
func setLocale(_ locale: Locale) throws
|
||||
}
|
||||
|
|
|
@ -41,6 +41,9 @@ open class StandardLocalizationService: LocalizationService {
|
|||
case lprojFileDoesNotExist(for: Locale)
|
||||
}
|
||||
|
||||
/**
|
||||
Change the service's locale.
|
||||
*/
|
||||
open func setLocale(_ locale: Locale) throws {
|
||||
guard let languageCode = locale.languageCode else { throw LocaleError.languageCodeIsMissing(for: locale) }
|
||||
guard loadBundle(for: languageCode) else { throw LocaleError.lprojFileDoesNotExist(for: locale) }
|
||||
|
@ -49,6 +52,9 @@ open class StandardLocalizationService: LocalizationService {
|
|||
notificationCenter.post(name: .localization(.localeDidChange), object: nil)
|
||||
}
|
||||
|
||||
/**
|
||||
Translate the provided key to a localized string.
|
||||
*/
|
||||
open func translate(_ key: String) -> String {
|
||||
translator.translate(key)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ public class StandardTranslator: Translator {
|
|||
|
||||
public init() {}
|
||||
|
||||
/**
|
||||
Translate the provided key to a localized string.
|
||||
*/
|
||||
public func translate(_ key: String) -> String {
|
||||
NSLocalizedString(key, comment: "")
|
||||
}
|
||||
|
|
|
@ -14,5 +14,8 @@ import Foundation
|
|||
*/
|
||||
public protocol Translator: AnyObject {
|
||||
|
||||
/**
|
||||
Translate the provided key to a localized string.
|
||||
*/
|
||||
func translate(_ key: String) -> String
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue