extension Text {
public init<S>(_ text: S) where S : StringProtocol {
let text = String(text)
let path = Bundle.main.path(forResource: "en", ofType: "lproj")
let bundle = Bundle(path: path!)
let translated = NSLocalizedString(text, tableName: "Localizable", bundle: bundle!, value: "", comment: "")
self.init(verbatim: translated)
}
2条答案
按热度按时间6yoyoihd1#
确保项目中有
Localizable.strings
文件。LocalizedStringKey
在这里查找键/值作为默认值。https://developer.apple.com/documentation/swiftui/localizedstringkey
如果要定义其他文件,请使用
字符串
初始化器和
tableName
应该匹配您的.strings
文件名。slhcrj9b2#
字符串