0

Despite all the info available on the web, I am still struggling to translate my hard-coded strings in Swift (target language: French) - How do I go about translating, for example, the title Week A in the following code:

let titleButton: UIButton = UIButton(frame: CGRectMake(0, 0, 100, 32))
    titleButton.setTitle("Week A", forState: UIControlState.Normal)
    titleButton.titleLabel?.font = UIFont(name: "CollegiateHeavyOutline", size: 25.0)

or the placeholder text in the following code:

timeTextField.placeholder = "Type in start time"

A step by step answer will be much much appreciated. Thanks in advance.

Laroms
  • 85
  • 1
  • 13

2 Answers2

1

the hard coded text would change to another language this is called localization. so you have to implement localization in your project. follow this link.

0

I made it - yes! I did the following:

let titleButton: UIButton = UIButton(frame: CGRectMake(0, 0, 100, 32))
    titleButton.setTitle(NSLocalizedString("WEEK_A", comment: "Name of the week A"), forState: UIControlState.Normal)
    titleButton.titleLabel?.font = UIFont(name: "CollegiateHeavyOutline", size: 25.0)

and for placeholder text:

timeTextField.placeholder = NSLocalizedString("TYPE_IN_START_TIME", comment: "start time")

Following the link in the accepted answer was really helpful!

Laroms
  • 85
  • 1
  • 13