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

Ios 应用程序小部件描述和名称本地化,ios,swift,swiftui,ios14,widgetkit,Ios,Swift,Swiftui,Ios14,Widgetkit,我想知道是否可以在本地化时使用应用程序语言,而不是电话语言 我说的是: .configurationDisplayName("widget.name".localized()) 及 是的,您可以为configurationDisplayName和description提供本地化字符串,因为它们也接受LocalizedStringKey参数: /// Sets the localized name shown for a widget when a user adds or

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

我说的是:

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


是的,您可以为
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
有关更多信息,请参阅:

  • 初始化语言设置后,您可以获得所需的正确翻译
  • 像这样表演:
    .configurationDisplayName(disName)

  • 如果它不起作用?你也可以“本地化”


  • 我说的是描述和名字。当使用这些时,本地化是在设备语言上完成的,我需要使用应用程序语言。我的意思是它可以工作-本地化可以工作,但本地化基于设备,而不是应用程序语言:)哦,我现在明白了-我认为我们还没有这种可能性。您可以将区域设置注入到视图环境中,但对于小部件来说这是不可能的。类似的线索如下:
    /// 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()
    }
    
    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)
            }
    
    }