gpt4 book ai didi

ios - 带参数的本地化字符串在参数周围添加换行符和括号

转载 作者:行者123 更新时间:2023-12-04 01:25:55 28 4
gpt4 key购买 nike

我正在尝试显示包含参数的本地化字符串。结果不是在一行中显示嵌入参数的字符串,而是一个断开的 3 行字符串:

预期结果:

The price is $9.99/year.

结果:
The price is (
"$9.99"
)/year.

Localizable.strings:
"price_string" = "The price is %@/year.";

称呼:
"price_string".localized(priceString)

哪里 priceString是一个字符串变量。

.localized()定义如下:
extension String {
var localized: String {
return NSLocalizedString(self, comment: "\(self)_comment")
}

func localized(_ args: CVarArg...) -> String {
return String(format: localized, args)
}
}

最佳答案

请看输出。它清楚地表明 price 参数是一个数组。并且确实是可变参数args被视为一个数组。

所以你只是使用了错误的 API

func localized(_ args: CVarArg...) -> String {
return String(format: localized, arguments: args)
}

关于ios - 带参数的本地化字符串在参数周围添加换行符和括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61932291/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com