0

I'm changing my app to make it localizable/internationalizable, by adding multiple languages, so I have some texts on the storyboard and others in the swift files, so I have to make them internationalizable, but I don't know how to keep a customized font and make it internationalizable.

I have created these: enter image description here

enter image description here

So if I understand the first strings files are for UILabel which are written in the storyboard. The second is for text in swift files also UIlabel linked in.

But I have to customize, fonts, colours... for some texts, and I don't know how to do for the UILabel in the storyboard, but for swift files I did it:

    var main_string = "VOTRE EXPERT DU\nREGROUPEMENT DE CRÉDITS\nEN FRANCE DEPUIS 1998."
    var string_to_color = "1998"
    var string_to_bold = "REGROUPEMENT DE CRÉDITS"

    var range_color = (main_string as NSString).range(of: string_to_color)

    var range_bold = (main_string as NSString).range(of: string_to_bold)

    let attributedString = [ NSAttributedStringKey.font: UIFont(name: "gotham-book", size: 18.0)! ]

    let myString = NSMutableAttributedString(string: "VOTRE EXPERT DU\nREGROUPEMENT DE CRÉDITS\nEN FRANCE DEPUIS 1998.", attributes: attributedString)
  NSLocalizedString("Welcome", comment: "")
    myString.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.orange , range: range_color)

    let font = UIFont(name: "gotham-bold", size: 18.0)
    myString.addAttribute(NSAttributedStringKey.font, value: font, range: range_bold)
    accueilTopLabel.attributedText = myString

But how can I manage different languages with? Because I use ranges so it looks difficult. What the best way to manage it?

Farhana Naaz Ansari
  • 7,524
  • 26
  • 65
  • 105
Ben
  • 761
  • 1
  • 12
  • 35
  • You should use benefits of `@IBInspectable` attribute. – CZ54 Apr 25 '18 at 13:25
  • @CZ54 I found nothing interesting about, here I found this: https://stackoverflow.com/questions/27397380/is-there-a-unicode-way-to-make-part-of-a-string-bold?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa but the number of characters are changed between languages – Ben Apr 25 '18 at 14:03
  • Je comprends pas vraiment ce que tu essaie de faire. Mettre des attributs sur certaines parties de la phrase ? – CZ54 Apr 25 '18 at 14:08
  • @CZ54 C'est simple par exemple je veux gérer 2 langues: "Bonjour et bienvenue" "Hello and welcome", donc j'aurais 2 fichiers de strings pour gérer l'internationalisation, mais comment mettre le "welcome" et "bonjour" en rouge et le "et" et "and" en gras ? – Ben Apr 25 '18 at 14:17
  • @CZ54 La ce que je vais faire c'est que au lieu d'avoir une traduction commune je vais diviser sa en 3 traductions je pense que c'est la meilleur solution pour que je m'en sorte – Ben Apr 25 '18 at 14:20
  • c'est soit ça soit tu crée tes balises ( genre * text * met text en gras, et tu utilise des regex pour catcher ca ) – CZ54 Apr 25 '18 at 14:42
  • @CZ54 donc il est possible de customiser le style directement dans le fichier strings ? – Ben Apr 25 '18 at 14:47
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169771/discussion-between-cz54-and-ben). – CZ54 Apr 25 '18 at 14:48

0 Answers0