Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder and NSLocalizedString

I'm trying to translate my application and I find it difficult to translate when there are half a placeholder. I need to locate the following code:

[textView1 insertText:[NSString stringWithFormat:@"%@ è il %i/%i/%i. Il giorno delle settimana è %@. La Festa è compresa nel calcolo. \n", nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

I put in the file localizable.string (English):

"festaCompresa" = @"%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

Then I edited the piece of code:

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresaW, @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

It does not work.

like image 958
Andrea Avatar asked Apr 30 '12 16:04

Andrea


2 Answers

Your strings file has a minor error, you've included an @ as though the string as an NSString constant - the file format uses strings in quotes:

"festaCompresa" = "%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

BTW: when creating format strings for localization you might need to use positional formats where each format specification includes the number of the argument. For example:

"festaCompresa" = "%1$@ is the %2$i/%3$i/%4$i. the day of the week is %@. The holidays is included in the calculation. \n";

This is obviously not required in the above string as the arguments are included in the order they are provided. However in some languages they might need to be in a different order and this is how it is done.

like image 96
CRD Avatar answered Oct 22 '22 19:10

CRD


Did you copy-paste the code? Or did you re-typed it in? Because if you copy-pasted it the problem is there:

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresaW, @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

I suppose it should be

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresa", @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

So basically a " instead of W.

Also, in Localizable.strings you don't put @ in front of the quotes, so this:

"festaCompresa" = @"%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

should be this:

"festaCompresa" = "%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

Hope it helps

like image 44
Novarg Avatar answered Oct 22 '22 20:10

Novarg