Suppose there is this string in English and its a requirement to bold or color etc. to a particular part of a string of text:
"word1 word2 WORD3 word4"
That can be accomplished by setting the attribute for the appropriate range.
The range could be hardcoded to (13,5) but then of course that wouldn't be localizable.
So alternatively the range could be dynamically determined by knowing that its the 3rd word that has to have the bold applied to it.
But that too isn't localizable. Suppose once that sentence is translated to language N it only contains 2 words, or contains 5 words in language M?
So my question is how can you use attributes strings in combination with localization without lots of hardcoding?
You could use some notation to signify which words should be bolded, and then have a transformer that would find ranges to bold and add appropriate attributes.
word •word• word word
מילה מילה •מילה• מילה מילה
In these two sentences, I use the character •
to signify that the word in between should be bold. I can then use rangeOfString:options:range:
to iterate and find all ranges to bold and insert an attribute accordingly.