iOS Xcode 多语言支持

Xcode 15还是14之后多语言就不用创建LocalString文件了,新的文件是Stirng CataLog,如下图:


image.png

通过使用对应的Api


/// Xcode can read through a project's code to find invocations of
/// `NSLocalizedString(_:tableName:bundle:value:comment:)` and automatically
/// generate the appropriate strings files for the project's base localization.
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
public func NSLocalizedString(_ key: String, tableName: String? = nil, bundle: Bundle = Bundle.main, value: String = "", comment: String) -> String

Xcode会自动帮我们生成对应的key和Value,如下图:


image.png

注意:不能对该方法封装或宏定义了,只能用这个系统的Api来用。

对于已经存在的项目而言,我们可以让Xcode帮我们把LocalString 文件转成 String CataLog。

image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。