27

How to add a newline character in localizable.strings?

I tried putting \n, but no success.

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Burhanuddin Sunelwala
  • 5,318
  • 3
  • 25
  • 51

4 Answers4

29

Using \n should just work. With this line in "Localizable.strings":

"abc" = "foo\nbar";

and this code:

NSString *s = NSLocalizedString(@"abc", NULL);
NSLog(@"%@", s);

I get the output

2013-05-02 14:14:45.931 test[4088:c07] foo
bar
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • I agree. True: key shouldn't include `\n` - and why would anyone want it there... everything else (`\n` in localized strings) should work just fine. – Rok Jarc May 02 '13 at 12:23
  • Adding \n works if you display the text in the UITextView, or UILabel. – Bonnie May 02 '13 at 12:23
  • I had enables HTML therefore, \n wasn't working. anyways after putting html tags its working absolutely fine! any idea how to add links? – Burhanuddin Sunelwala May 03 '13 at 06:13
20

Just adding newlines in the .strings file also works

"str" = "Hi ,

this is .

in a new line,

";   
Bonnie
  • 4,943
  • 30
  • 34
3

This works in an UILabel and UITextview as long as you set the appropriate line number:

testLabel.numberOfLines = 2;

You could also set this to 0 which is automatic line count, also you should ensure that your label is big enough to show multiple lines, or else it will be cut off.

Maschel
  • 137
  • 4
1

this will not work in localizable.strings you have to create two keys and then only you can manage \n between two localizable strings during the concatination of strings.

Divyam shukla
  • 2,038
  • 14
  • 18
  • This one helped me.! By creating 2 keys. `"someLocalised1" = "Some Localised 1";` & `"someLocalised2" = "Some Localised 2";` I wonder for few other strings it is working with \n. God knows Apple is cooking inside Xcode. – Yash Bedi Nov 09 '20 at 14:32