1. 确保localization中添加了多语言
2. 添加localisable.strings文件
3.选择这个文件,勾选多语言即可
4.打开localisable.strings文件,添加一些测试字符串:
5. 添加helper函数 :
使用:
在mainlayout中字符串的本地化:
原文链接:https://www.f2er.com/swift/321424.html2. 添加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" = "修改密码"; ...