Categories: 技术原创

iOS字符串国际化更改占位符对应的参数

最近端时间在做国际化,遇到不同语言中如果要使语法通顺,就必须要更改占位符对应的参数顺序

如下句子在英文的时候没有问题,但是如果是中文,参数顺序就倒过来了

1
"Congratulations! You have got the %@ Verification on %@ %@."

怎么解决呢,在对应语言的.strings文件中加上 (下标 + $)就好,这里需要注意下标从1开始,不是从0开始,如下

1
"Congratulations! You have got the %@ Verification on %@ %@." = "你在%3$@ %2$@获得了%1$@认证!";

代码如下,参数顺序不用改变

1
String(format: LGLocalizedString("Congratulations! You have got the %@ Verification on %@ %@."), verifyType, LGLocalizedString(dayArray[verifyDate.day - 1]), LGLocalizedString(monthArray[verifyDate.month - 1]))
龚杰洪

Recent Posts

GOLANG面试八股文-代码面试题整理

1. 切片底层数据结构问题 […

3 周 ago

GOLANG面试八股文-性能相关

Golang 的性能优化是一个…

3 周 ago

GOLANG面试八股文-定时器相关

在 Golang 的开发中,定…

3 周 ago