2011-06-06 31 views
1
//Viewcontroller.m code 
NSLocalizedString(@"attributes",@"Attribute Name") 

//Localizable.string code 
"attributes"="attributes-french"; 

這種方法的變量NSLocalizedString Problem-本地化本地化的偉大工程@「屬性」持有字符串

現在應該是什麼代碼,如果我想用一個變量

我我正在使用

//Viewcontroller.m code 
NSString *[email protected]"attributes" 
NSLocalizedString(Value,@"Attribute Name"); 

//Localizable.string code 
"Value"="Value-french"; 

這不起作用。有人能告訴我使用NSLocalizdString本地化一個變量(包含一個字符串)的正確方法嗎?

回答

1

您無法本地化變量名稱。您只能根據變量的值進行本地化。所以,你的Localizable.strings應該包含

"attributes"="attributes-french" 

如果有的話,你可以改變使用%@描述here字符串的部分。

0

調用NSLocalizedString沒有問題,而是在您的Localizable.strings文件中定義。

由於您將變量Value定義爲「屬性」,因此該函數將用作查找正確本地化字符串的關鍵字。

這應該正常工作:

//Viewcontroller.m code 
NSString *[email protected]"attributes" 
NSLocalizedString(Value,@"Attribute Name"); 

//Localizable.string code 
"attributes"="Value-french"; 

我在斯威夫特,然後看起來像這樣類似的測試代碼:

//Viewcontroller.swift code 
let Value="attributes" 
NSLocalizedString(Value, comment:"Attribute Name") 

//Localizable.string code 
"attributes"="Value-french"; // <- don't forget the semicolon!