Swift中的本地化实现
发布时间:2020-12-14 02:30:47 所属栏目:百科 来源:网络整理
导读:1. 确保localization中添加了多语言 2. 添加localisable.strings文件 3.选择这个文件,勾选多语言即可 4.打开localisable.strings文件,添加一些测试字符串: localisable.strings (base)"LoginError" = "Error Login";"UserNameEmpty" = "Username Empty";"
1. 确保localization中添加了多语言 2. 添加localisable.strings文件
3.选择这个文件,勾选多语言即可 4.打开localisable.strings文件,添加一些测试字符串: localisable.strings (base) "LoginError" = "Error Login"; "UserNameEmpty" = "Username Empty"; "PasswordEmpty" = "Password Empty"; "GetUserInfoError" = "Error Getting User Info"; localisable.strings (english) "LoginError" = "Error Login"; "UserNameEmpty" = "Username Empty"; "PasswordEmpty" = "Password Empty"; "GetUserInfoError" = "Error Getting User Info"; localisable.strings (chinese) "LoginError" = "登录错误"; "UserNameEmpty" = "用户名不能为空"; "PasswordEmpty" = "密码不能为空"; "GetUserInfoError" = "获取用户信息错误"; 5. 添加helper函数 : func localized() -> String{ return NSLocalizedString(self,comment: "") } 使用: "LoginError".localized(); 在mainlayout中字符串的本地化: ... /* Class = "UIButton"; normalTitle = "Button"; ObjectID = "oYr-T8-Q59"; */ "oYr-T8-Q59.normalTitle" = "登录"; /* Class = "UIButton"; normalTitle = "CHANGE PASSWORD"; ObjectID = "pzP-ri-GfN"; */ "pzP-ri-GfN.normalTitle" = "修改密码"; ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |