Skip to content

Commit

Permalink
Support Localization with Text
Browse files Browse the repository at this point in the history
  • Loading branch information
lkzhao committed Nov 5, 2022
1 parent 9cccb92 commit b97ba63
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sources/UIComponent/Components/View/Text.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit b97ba63

Please sign in to comment.