如何使用格式化占位符本地化字符串? [英] How do I localize a string with formatting placeholders?

查看:139
本文介绍了如何使用格式化占位符本地化字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用NSLocalizedString本地化其中包含占位符的字符串?

How do I localize a string that has placeholders in it with NSLocalizedString?

例如:

[NSString stringWithFormat:@"You can afford %i at %@%li.",[kCash integerValue]/self.price, kYen,  self.price]

我如何本地化?我是否将字符串分解为多个本地化字符串?那么我如何处理不同的句子结构和语法?

How do I localize this? Do I do break up the strings into multiple localized strings? How then do I deal with varying sentence structure and grammar?

推荐答案

让本地化的字符串包含占位符。这几乎是唯一适当的方式,正如你所提到的,你不能考虑不同的词序。

Have the localized strings include the placeholders. That's pretty much the only proper way to do it as otherwise, as you mentioned, you couldn't take varying word order into account.

这些方面的东西:

[NSString stringWithFormat:NSLocalizedString(@"Foo %i", @"Foo %i"), 123]

这篇关于如何使用格式化占位符本地化字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆