Skip to content

Commit 73438f7

Browse files
committed
Change attributtedString formatting for better L10n
1 parent ac03b13 commit 73438f7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

WooCommerce/Classes/ViewModels/CardPresentPayments/CardPresentModalScanningForReader.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,24 @@ final class CardPresentModalScanningForReader: CardPresentPaymentsModalViewModel
2222
let auxiliaryButtonTitle: String? = nil
2323

2424
var auxiliaryAttributedButtonTitle: NSAttributedString? {
25-
let moreLinkAttributes: [NSAttributedString.Key: Any] = [
26-
.foregroundColor: UIColor.accent,
27-
.underlineStyle: NSUnderlineStyle.single.rawValue
28-
]
29-
let moreTextAttributes: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.text]
30-
let linkAttributedString = NSMutableAttributedString(string: Localization.learnMoreLink, attributes: moreLinkAttributes)
31-
let moreAttributedString = NSMutableAttributedString(string: Localization.learnMoreText, attributes: moreTextAttributes)
32-
linkAttributedString.append(moreAttributedString)
33-
return linkAttributedString
25+
let result = NSMutableAttributedString(
26+
string: .localizedStringWithFormat(
27+
Localization.learnMoreText,
28+
Localization.learnMoreLink
29+
),
30+
attributes: [.foregroundColor: UIColor.text]
31+
)
32+
result.replaceFirstOccurrence(
33+
of: Localization.learnMoreLink,
34+
with: NSAttributedString(
35+
string: Localization.learnMoreLink,
36+
attributes: [
37+
.foregroundColor: UIColor.accent,
38+
.underlineStyle: NSUnderlineStyle.single.rawValue
39+
]
40+
))
41+
result.addAttribute(.font, value: UIFont.footnote, range: NSRange(location: 0, length: result.length))
42+
return result
3443
}
3544

3645
let bottomTitle: String? = Localization.instruction
@@ -94,10 +103,12 @@ private extension CardPresentModalScanningForReader {
94103
)
95104

96105
static let learnMoreText = NSLocalizedString(
97-
" about In\u{2011}Person Payments",
106+
"%1$@ about In\u{2011}Person Payments",
98107
comment: """
99-
A label prompting users to learn more about In-Person Payments"
108+
A label prompting users to learn more about In-Person Payments.
100109
\u{2011} is a special character that acts as nonbreaking hyphen for "-" in the "In-Person" string.
110+
%1$@ is a placeholder that always replaced with \"Learn more\" string,
111+
which should be translated separately and considered part of this sentence.
101112
"""
102113
)
103114
}

0 commit comments

Comments
 (0)