4

I am doing language translation in code.

self.title.text = [NSString stringWithFormat:NSLocalizedString(@"Q%ld", nil), (long)quizNumber];

I have added localization which works fine in French case but in Chinese '%ld' comes on the screen.

If I put the chinese string in place of english string, I get error "data argument not used by format string"

Any pointers? Should I use some kind of encoding?

A_G
  • 2,260
  • 3
  • 23
  • 56
  • I think that you are doing it wrong. You want `self.title.text = NSLocalizedString([NSString stringWithFormat:@"Q%ld", (long)quizNumber], nil);` – Larme Mar 03 '17 at 11:20
  • @Larme Your statement does not compile! – A_G Mar 03 '17 at 11:22
  • `NSString *translationKey = [NSString stringWithFormat:@"Q%ld", (long)quizNumber]; self.title.text = NSLocalizedString(translationKey, nil);`? – Larme Mar 03 '17 at 11:25
  • Tried. Did not work. In fact this gives the english string because %ld is substituted before localization – A_G Mar 03 '17 at 11:32
  • However, if %ld is in the starting of the string then it is translated perfectly to chinese. – A_G Mar 03 '17 at 11:46
  • 1
    Could you show what's your Localizable.strings ? – Larme Mar 03 '17 at 15:18

1 Answers1

2

I have done localisation in my app in Chinese as well, no problem so far, but I use mostly %d, not %ld.

Can you try using %d instead?

self.title.text = [NSString stringWithFormat:NSLocalizedString(@"Q%d", nil), (int)quizNumber];

Take a look at https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

JackyW
  • 345
  • 2
  • 11