user1254529
user1254529

Reputation:

Xcode iPhone specific nslocalized string not working

In one of my xCode projects I want the App when it starts to select a random number between 0 to X and then it this number will appear in a NSLocalizedstring that will display a random sentence in a textfield.

But when I run the App, only the key is returned to me (introX).

Here is my code (in ViewDidLoad):

introNumber = rand() % 4; //Selects random number

textView.text = [NSString stringWithFormat:NSLocalizedString(@"intro%i", nil), introNumber]; //Put the random number right in the NSLocalizedString

All my introduction sentences are written that way in the Localized.string file:

"intro0" = "...";

"intro1" = "...";

...

"introX" = "...";

First, can we do variable NSLocalizedStrings?

Then, where is the mistake? ;))

Regards,

Upvotes: 1

Views: 579

Answers (1)

rckoenes
rckoenes

Reputation: 69459

You are doing to the wrong way round, first make the key for the translation then get the localized string:

introNumber = rand() % 4; //Selects random number
NSString *translateKey  = [NSString stringWithFormat:@"intro%i", introNumber];
textView.text = NSLocalizedString(translateKey, @"");

Upvotes: 0

Related Questions