1

I couldn't find any hint to this quite specific question: How can I set the grammar rule by which hyphenation on a UILabel is performed?

You see, my app is localised for english and german language and contains german street names (which obviously will not be translated to english). When the language of the device is set to german, the hyphenation works fine.

But on a device with language set to english, the hyphenation seems to struggle with the german street names (meaning: hyphenation is happening, but in a grammatically wrong way). I assume that's because it is derived from the language set in iOS preferences.

here's how I perform the hyphenation on that label:

func updateStreetNameLabel(streetName: String) {

    let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
    paragraphStyle.hyphenationFactor = 1.0
    paragraphStyle.alignment = .Center

    let streetNameWithHyphens: NSMutableAttributedString = NSMutableAttributedString(string: streetName, attributes: [NSParagraphStyleAttributeName : paragraphStyle])

    streetNameLabel.attributedText = streetNameWithHyphens

}

I would have thought there was a specific attribute to do this, but I was not able to find out how to go about it. Thanks for any help with this tiny but tricky problem! S.

1 Answers1

0

You can set the user's language preference from within your app, although it's not recommended. A better, but a lot more painful, solution is to add the German place names, with English hyphenation rules, to the user's dictionary, if that's even possible. But the best solution is probably to turn hyphenation off when the app is running in English.

Community
  • 1
  • 1
NRitH
  • 13,441
  • 4
  • 41
  • 44