美文网首页
[9] String Resources(本地化文件资源)

[9] String Resources(本地化文件资源)

作者: coderzcj | 来源:发表于2017-09-28 17:13 被阅读9次

创建 Strings 文件

使用命令行工具genstrings

genstrings -o en.lproj *.m

使用自定义 Strings 文件

Custom.strings文件中定义:

/* A comment */
"Yes" = "Oui";
"The same text in English" = "Le même texte en anglais";

在代码中使用:

NSString* theString;
theString = NSLocalizedStringFromTable (@"Yes", @"Custom", @"A comment");

格式化

"Windows must have at least %d columns and %d rows." =
"Les fenêtres doivent être composes au minimum de %d colonnes et %d lignes.";
"File %@ not found." = "Le fichier %@ n’existe pas.";

添加n$可以指定顺序,n表示参数位置

/* Message in alert dialog when something fails */

"%@ Error! %@ failed!" = "%2$@ blah blah, %1$@ blah!";

调试

使用命令行工具plutil

plutil *.strings

参考

String Resources

相关文章

网友评论

      本文标题:[9] String Resources(本地化文件资源)

      本文链接:https://www.haomeiwen.com/subject/onkvextx.html