gpt4 book ai didi

SwiftUI,如何翻译带有计时器样式的文本?

转载 作者:行者123 更新时间:2023-12-04 03:53:03 25 4
gpt4 key购买 nike

我们正在尝试创建一个 iOS 14 WidgetKit ,由于 API 的限制,我们无法使用计时器,但是我们发现我们可以使用带有 Date 样式的 Text 来更新自身,但是可用的文档和文本很少似乎无法适应手机语言。
从 Xcode 内部接口(interface):

@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
extension Text {

/// A predefined style used to display a `Date`.
public struct DateStyle {

/// A style displaying only the time component for a date.
///
/// Text(event.startDate, style: .time)
///
/// Example output:
/// 11:23PM
public static let time: Text.DateStyle

/// A style displaying a date.
///
/// Text(event.startDate, style: .date)
///
/// Example output:
/// June 3, 2019
public static let date: Text.DateStyle

/// A style displaying a date as relative to now.
///
/// Text(event.startDate, style: .relative)
///
/// Example output:
/// 2 hours, 23 minutes
/// 1 year, 1 month
public static let relative: Text.DateStyle

/// A style displaying a date as offset from now.
///
/// Text(event.startDate, style: .offset)
///
/// Example output:
/// +2 hours
/// -3 months
public static let offset: Text.DateStyle

/// A style displaying a date as timer counting from now.
///
/// Text(event.startDate, style: .timer)
///
/// Example output:
/// 2:32
/// 36:59:01
public static let timer: Text.DateStyle
}

/// Creates an instance that displays localized dates and times using a specific style.
///
/// - Parameters:
/// - date: The target date to display.
/// - style: The style used when displaying a date.
public init(_ date: Date, style: Text.DateStyle)

/// Creates an instance that displays a localized range between two dates.
///
/// - Parameters:
/// - dates: The range of dates to display
public init(_ dates: ClosedRange<Date>)

/// Creates an instance that displays a localized time interval.
///
/// Text(DateInterval(start: event.startDate, duration: event.duration))
///
/// Example output:
/// 9:30AM - 3:30PM
///
/// - Parameters:
/// - interval: The date interval to display
public init(_ interval: DateInterval)
}
我们的代码:
Text(entry.end!, style: .relative)
渲染:
iOS image of widget
我们需要将此文本调整为电话区域设置(屏幕截图中为德语),有人做到了吗?

最佳答案

无需担心本地化,在模拟器上它采用 macOS 语言配置,但在设备上它采用设备语言。

关于SwiftUI,如何翻译带有计时器样式的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64157325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com