2012-04-30 167 views
6

我想翻譯我的應用程序,我發現很難翻譯時,有一半的佔位符。我需要找到下面的代碼:佔位符和NSLocalizedString

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

我把文件localizable.string(英文):

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

然後我編輯了一段代碼:

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

它不起作用。

+0

如何它確實不起作用? – hamstergene

+0

屏幕顯示不正確,因爲單詞compare:festaCompresaW – Andrea

+0

此文件中還存在錯誤。字符串:驗證失敗:數據無法讀取,因爲它已損壞。 – Andrea

回答

4

您是否複製粘貼代碼?還是你重新輸入了?因爲如果你複製粘貼它的問題是存在的:

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

我想這應該是

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

的所以基本上一個"代替W

此外,在Localizable.strings你不把@在引號前面,所以這樣的:

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

應該是這樣的:

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

希望它可以幫助

6

您的字符串文件中有一個小錯誤,你已經包括在@彷彿字符串作爲NSString不變 - 文件格式使用字符串引號:

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

BTW:創建本地化格式的字符串時您可能需要使用位置格式,其中每個格式規範都包含參數的編號。例如:

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

這顯然不是上述字符串所要求的,因爲參數按提供的順序包含在內。但是在某些語言中,它們可能需要按照不同的順序進行,這是如何完成的。