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