winklerrr
winklerrr

Reputation: 14717

Formatted NSLocalizedString with variable value

I'm new to Objective-C. Here is my question:

In my two string files are the following two entries:

(German string file)

/* Class = "IBUILabel"; text = "Import to DoS"; ObjectID = "GfF-rD-aDa"; */
"GfF-rD-aDa.text" = "Zu DT %lu importieren";

(English string file)

/* Class = "IBUILabel"; text = "Import to DoS"; ObjectID = "GfF-rD-aDa"; */
    "GfF-rD-aDa.text" = "Import to DoS %lu";

My code looks like:

self.importLabel.text = [NSString localizedStringWithFormat:NSLocalizedString(@"GfF-rD-aDa.text", nil), projectday];

According to Apples Documentation NSLocalizedString needs a key and a comment. That's why I putted @"GfF-rD-aDa.text" into the first parameter because it's the same key like in my strings file.

So I want it to generate strings like:

"Zu DT 2 importieren"

and

"Import to DoS 2"

but it doesn't work. The output text is:

"GfF-rD-aDa.text"

I'm not allowed to change the key in the strings table because we use a script to generate all these entries based on the object id.

Regards

Upvotes: 1

Views: 512

Answers (2)

Zahid
Zahid

Reputation: 562

Try using this specify your strings file in NSLocalizedStringFromTable macro.

 self.importLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"GfF-rD-aDa.text", @"yourStringsFile", @"comment"), projectday];

Upvotes: 1

peig
peig

Reputation: 418

Try this:

self.importLabel.text = [NSString stringWithFormat:NSLocalizedString(@"GfF-rD-aDa.text", nil), projectday];

Upvotes: 1

Related Questions