mac-cain13 / R.swift

Strong typed, autocompleted resources like images, fonts and segues in Swift projects
MIT License
9.49k stars 763 forks source link

Formatting only part of a string using R.string.localizable #876

Closed nicobelo91 closed 4 days ago

nicobelo91 commented 9 months ago

Let's say I have the following text in the Localizable.swift file: "name" = "My name is %@"; I'd like to make the part where the name would go bold, so that it would read something like "My name is Mark" whenever I use R.string.localizable.name("Mark"). Is there a way to do that using R.swift?

nicolasvergoz-leo commented 3 months ago

With markdown maybe ? "My name is %@"

tomlokhorst commented 4 days ago

R.swift has no special support for formatting.

But you can use the existing APIs like AttributedString.

For example:

// Localizeable.strings
"name" = "My name is **%@**";
// ContentView.swift
if let attributedString = try? AttributedString(markdown: R.string.localizable.name("Mark")) {
    Text(attributedString)
}