1
我有本土化的問題,本地化字符串中的iOS
這裏是我的代碼:
func attributedText()->NSAttributedString{ <br>
self.lbltext.text =
NSLocalizedString("\n" + 「Best Friends「 + "\n" + "\n" + 「James」 + 「Kelvin」 +「Favorite Food」 + "\n" + "\n" +"(1) Burger」 + "\n" +"(2) Fried Food」 + "\n" +"(3) Beer」, comment: "")
let string = "\n" + 「Best Friends「 + "\n" + "\n" + 「James」 + 「Kelvin」 + 「Favorite Food」 + "\n" + "\n" +
"(1) Burger」 + "\n" +
"(2) Fried Food」 + "\n" +
"(3) Beer」 as NSString<br><br>
let attributedString = NSMutableAttributedString(string: string as String, attributes: [NSFontAttributeName:UIFont.systemFontOfSize(14.0)])
let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFontOfSize(17.0)]
//字符串的一部分要大膽
attributedString.addAttributes(boldFontAttribute, range: string.rangeOfString(「Best Friends「))
attributedString.addAttributes(boldFontAttribute, range: string.rangeOfString(「Favorite Food」))
return attributedString
}<br><br>
self.lbltext = attributedText()
=== =================
In Main.strings文件,我的代碼是
/* Class = "UILabel"; text = "\n" + 「Best Friends「 + "\n" + "\n" + 「James」 + 「Kelvin」 +「Favorite Food」 + "\n" + "\n" + "(1) Burger」 + "\n" + "(2) Fried Food」 + "\n" + "(3) Beer」; ObjectID = "kDi-LM-j5f"; */ <br><br>
"kDi-LM-j5f.text" = "\n" + 「Best Friends「 + "\n" + "\n" + 「James」 + 「Kelvin」 + 「Favorite Food」 + "\n" + "\n" + "(1) Burger」 + "\n" + "(2) Fried Food」 + "\n" +"(3) Beer」; <br>
=======================
在本地化.strings file,
"\n" + 「Best Friends「 + "\n" + "\n" + 「James」 + 「Kelvin」 + 「Favorite Food」 + "\n" + "\n" +"(1) Burger」 + "\n" +"(2) Fried Food」 + "\n" +"(3) Beer」 = "my translate text....";
錯誤的數據格式是錯誤的。
我認爲這是由於「\ n」引起的。