Many languages have spaces between words, so it's easy to know when to wrap to a new line. For example, in english, any space represents an opportunity to wrap lines.
However, languages like Thai have wrapping between words, but no spaces to tell you when to wrap.
I am using a speech to text algorithm to transcribe audio into strings, then split it into line-by-line captions based on timestamps. For the first set of languages, this is pretty easy, using spaces to split up tokens. But I am worried that for Southeast Asian users, it will produce unintelligible splits between lines.
For these languages, is it possible to find the points in a string of text at which you would potentially be able to break the lines up? I have to assume this is somehow done internally for UIKit, otherwise, Thai users putting text into a UILabel would have incorrect line breaks.
See below for an explanation and visual example.

NLTokenizercan split text into words.Output:
In your real code, you could use the upper bound of each word range as the "word boundary". Alternatively, since you are doing captions, it might be more suitable to use:
to get the word range at a particular
index, whereindexcould be somewhere near your desired cut-off point, and you "cut the string off" atlastWordRange.upperBound.