I want to give a label a text that have multiple fonts in it. This can be accomplished by creating a NSMutableAttributedString
. However, I am not sure how I format the following case:
String(format: NSLocalizedString("%@ has replied in '%@'", comment: ""), username, conversationTitle)
I want to give the username and conversation title a separate font. I want to do this in the less buggiest way. What I mean by this:
- I do not want to find out the
username
later on in the string by using a substring. This is causing issues when theconversationTitle
is the same as theusername
, or theconversationTitle
is in theusername
etc. etc.. - I do not want to build up the string, as seen here: https://stackoverflow.com/a/37992022/7715250. This is just bad when creating
NSLocalizedString's
, I think the translators are going to have a bad time when string are created like that.
Questions like: Making text bold using attributed string in swift, Are there approaches for using attributed strings in combination with localization? and others are mostly string literals without NSLocalizedString
or NSLocalizedString
with parameters.