在Swift中添加行情

有一个简单的方法在Swift中添加引号到一个string? 引号应根据用户的语言设置正确定位(请参阅https://en.wikipedia.org/wiki/Quotation_mark )。 我想在添加引号后在UILabel中显示string。

例如:

var quote: String! quote = "To be or not to be..." // one or more lines of code that add localized quotation marks 

对于法国用户: “成为或不是…”

对于一个德国用户: “要不要……”

使用来自http://nshipster.com/nslocale/的信息:

 let locale = NSLocale.currentLocale() let qBegin = locale.objectForKey(NSLocaleQuotationBeginDelimiterKey) as? String ?? "\"" let qEnd = locale.objectForKey(NSLocaleQuotationEndDelimiterKey) as? String ?? "\"" let quote = qBegin + "To be or not to be..." + qEnd print(quote) 

样品结果:

区域设置输出

 德“是或不是...”
 恩“是或不是......”
  fr«是或不是...»
  ja「是或不是」

我不知道一个语言环境是否可以定义开始/结束分隔符。 在这种情况下,上面的代码将回落到正常的双引号"

 let quote = "\"To be or not to be...\"" println(quote) 

输出将是:“是或不是…”