应用程序小部件描述和名称本地化



我想知道是否可以在本地化时使用应用程序语言,而不是手机语言?

我说的是:

.configurationDisplayName("widget.name".localized())

.description("widget.description".localized())

是的,您可以向configurationDisplayNamedescription提供本地化字符串,因为它们也接受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

有关更多信息,请参阅:

  • SwiftUI中的本地化
  • 如何在Swift UI中实现本地化
  1. 初始化语言设置后,您可以获得所需的正确翻译
var disName: String {
LoadLocalizeSettings()
return "disName.key".localize()
}
  1. 执行如下:.configurationDisplayName(disName)

  2. 如果它不起作用?你也可以吊舱"本地化">

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)
}
}

相关内容

  • 没有找到相关文章

最新更新