Placeholder and NSLocalizedString

I am trying to translate my application and it is difficult for me to translate it when there is half a placeholder. I need to find 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 the localizable.string file (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 code snippet:

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

This does not work.

+6
source share
2 answers

Have you copied the paste code? Or did you retype it? Because if you copied 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 do not put @ in front of quotation marks, so this is:

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

should be as follows:

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

Hope this helps

+4
source

There is a minor error in the strings file, you included @ , as if the string was an NSString constant - the file format uses quoted strings:

 "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 may need to use positional formats, where each format specification includes an argument number. For instance:

 "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 line above, since the arguments are included in the order in which they are specified. However, in some languages ​​they may need to be in a different order, and so it is.

+6
source

Source: https://habr.com/ru/post/914559/


All Articles