最近端时间在做国际化,遇到不同语言中如果要使语法通顺,就必须要更改占位符对应的参数顺序
如下句子在英文的时候没有问题,但是如果是中文,参数顺序就倒过来了
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])) |