【发布时间】:2020-10-21 10:17:09
【问题描述】:
我想知道是否可以在本地化时使用应用语言,而不是手机语言?
我说的是:
.configurationDisplayName("widget.name".localized())
和
.description("widget.description".localized())
【问题讨论】:
标签: ios swift swiftui ios14 widgetkit
我想知道是否可以在本地化时使用应用语言,而不是手机语言?
我说的是:
.configurationDisplayName("widget.name".localized())
和
.description("widget.description".localized())
【问题讨论】:
标签: ios swift swiftui ios14 widgetkit
是的,您可以为configurationDisplayName 和description 提供本地化字符串,因为它们也接受LocalizedStringKey 参数:
/// Sets the localized name shown for a widget when a user adds or edits
/// the widget.
///
/// - Parameter displayName: The key for the localized name to display.
/// - Returns: A widget configuration that includes a descriptive name for
/// the widget.
public func configurationDisplayName(_ displayNameKey: LocalizedStringKey) -> some WidgetConfiguration
/// Sets the localized description shown for a widget when a user adds or
/// edits the widget.
///
/// - Parameters:
/// - descriptionKey: The key for the localized description to display.
/// - Returns: A widget configuration with a description of the widget.
public func description(_ descriptionKey: LocalizedStringKey) -> some WidgetConfiguration
欲了解更多信息,请参阅:
【讨论】:
var disName: String {
LoadLocalizeSettings()
return "disName.key".localize()
}
像这样执行:
.configurationDisplayName(disName)
如果它不起作用?你也可以 pod 'Localize'
func LoadLocalizeSettings() {
Localize.shared.update(provider: .strings)
Localize.shared.update(bundle: bundle)
Localize.shared.update(fileName: filename)
if let language = youWantThis {
update(language)
}
else {
update(.english)
}
}
【讨论】: