From b97ba63f0cef462e27735f65e162fa4f8ff89412 Mon Sep 17 00:00:00 2001 From: Luke Zhao Date: Sat, 5 Nov 2022 09:53:55 -0700 Subject: [PATCH] Support Localization with Text --- .../UIComponent/Components/View/Text.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sources/UIComponent/Components/View/Text.swift b/Sources/UIComponent/Components/View/Text.swift index 6946427f..d5f08da1 100644 --- a/Sources/UIComponent/Components/View/Text.swift +++ b/Sources/UIComponent/Components/View/Text.swift @@ -6,6 +6,30 @@ public struct Text: ViewComponent { public let attributedText: NSAttributedString public let numberOfLines: Int public let lineBreakMode: NSLineBreakMode + + @available(iOS 16, *) + public init( + localized: String.LocalizationValue, + font: UIFont = UIFont.systemFont(ofSize: UIFont.systemFontSize), + numberOfLines: Int = 0, + lineBreakMode: NSLineBreakMode = .byWordWrapping + ) { + self.attributedText = NSAttributedString(string: String(localized: localized), attributes: [.font: font]) + self.numberOfLines = numberOfLines + self.lineBreakMode = lineBreakMode + } + + @available(iOS 15, *) + public init( + _ attributedText: AttributedString, + numberOfLines: Int = 0, + lineBreakMode: NSLineBreakMode = .byWordWrapping + ) { + self.attributedText = NSAttributedString(attributedText) + self.numberOfLines = numberOfLines + self.lineBreakMode = lineBreakMode + } + public init( _ text: String, font: UIFont = UIFont.systemFont(ofSize: UIFont.systemFontSize),