摘自cocoa programming for mac os x 3rd

用格式化串标明 Token 的顺序

把文本是从一种语言转换为另一种语言时,因为语序的变化,词句也会出现相应变化。例如 语句:“Ted wants a scooter. ”,在另一种语言中语序可能是“A scooter is what Ted wants ”。 假如您尝试像这样本地化格式字符串:

NSString * theFormat = NSLocalizedString(@"WANTS", @"%@ wants a %@"); x = [NSString stringWithFormat:theFormat, @"Ted", @"Scooter"];

在第一种语言中,这可以工作得很好:

"WANTS" = "%@ wants a %@";

但在第二种语言中,你需要显示的标明插入 token 的位置,token 包含 1 个数字和 1 $符号: "WANTS" = "A %2$@ is what %1$@ wants".

相关文章:

  • 2021-08-22
  • 2021-11-12
  • 2021-11-30
  • 2021-07-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案