0

I'm looking for an information that I haven't found on the Internet. I would like to know in which iOS version did NSLocalizedString appear ? (maybe it's here since the first version of iOS ?)

I also would like to know in which case using localization in the .xib and in which case using NSLocalizedString ?

I'm asking this question because I'm working on an iOS project using localization in the .xib files AND NSLocalizedString, and I don't really know why the two methods are used... (it's an old project, that's why I'm asking the first question ^^)

Last question, for a new project, which one of these two methods would be your preferred one ?

Sorry for all this questions, and thanks for the answer ! =)

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Aïto
  • 1
  • 2

4 Answers4

0

Localisation using xib files is used when we want to localise elements on a UI e.g., when you want to show different images which has a localised text for a particular UIButton.
You can achieve this using localised xib files. There will be separate xib files for each language. And when you are setting any text on the UI from you controller, NSLocalizedString.
I hope this helps.

shoan
  • 1,303
  • 15
  • 22
0

NSLocalizedString was first available in 10.0

So I localize programmatically w/ NSLocalizedString because this way I can have all of my strings in one location.

Instead of through .xib localization generation, because with that you'll have a strings file for each xib you have.

However, if you have a .xib that you aren't modifying programmatically (i.e you don't have a custom class set as the file's owner), then you won't be able to programmatically set the NSLocalizedStrings. In which case, you will have to generate the strings files through the .xib.

Also, it is slightly more difficult to access string files associated with a .xib because it's directly connected with the .xib

A O
  • 5,516
  • 3
  • 33
  • 68
0

NSLocalizedString exists since iOS 1.

Basically you need NSLocalizedString for all dynamically created strings.

In a new project I'd recommend AutoLayout and Base Localization. There is one .xib file and all localizations – and layout adjustments – are performed at runtime via .strings files

vadian
  • 274,689
  • 30
  • 353
  • 361
0

Probably this question is dead but I jumped here searching for a method to localize xib strings and this page was the first result.

You can use both NSLocalizedString and xib. Have a look a this answer:https://stackoverflow.com/a/21443515/907720 discussed in detail here: https://medium.com/zendesk-engineering/ios-how-to-add-adaptive-constraints-to-support-a-universal-app-273663475b12

makeroo
  • 509
  • 8
  • 10