diff --git a/Bark.xcodeproj/project.pbxproj b/Bark.xcodeproj/project.pbxproj index ee99cbc..2267c06 100644 --- a/Bark.xcodeproj/project.pbxproj +++ b/Bark.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 0637FA8620E0AB6600E80174 /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8520E0AB6600E80174 /* UIColor+Extension.swift */; }; 0637FA8A20E0D58800E80174 /* NewServerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8920E0D58800E80174 /* NewServerViewController.swift */; }; 0637FA8C20E0D7A700E80174 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8B20E0D7A700E80174 /* BaseViewController.swift */; }; + 063C499520E36BF9001BCA35 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 063C499720E36BF9001BCA35 /* Localizable.strings */; }; 0661A543204FDA4100965E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0661A542204FDA4100965E4E /* AppDelegate.swift */; }; 0661A545204FDA4100965E4E /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0661A544204FDA4100965E4E /* HomeViewController.swift */; }; 0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; }; @@ -43,6 +44,8 @@ 0637FA8520E0AB6600E80174 /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = ""; }; 0637FA8920E0D58800E80174 /* NewServerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewServerViewController.swift; sourceTree = ""; }; 0637FA8B20E0D7A700E80174 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; + 063C499620E36BF9001BCA35 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = ""; }; + 063C499820E36C15001BCA35 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = ""; }; 0661A53F204FDA4100965E4E /* Bark.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bark.app; sourceTree = BUILT_PRODUCTS_DIR; }; 0661A542204FDA4100965E4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 0661A544204FDA4100965E4E /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = ""; }; @@ -134,6 +137,7 @@ 0661A549204FDA4100965E4E /* Assets.xcassets */, 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */, 0661A54E204FDA4100965E4E /* Info.plist */, + 063C499720E36BF9001BCA35 /* Localizable.strings */, ); path = Bark; sourceTree = ""; @@ -208,6 +212,7 @@ knownRegions = ( en, Base, + "zh-Hans", ); mainGroup = 0661A536204FDA4100965E4E; productRefGroup = 0661A540204FDA4100965E4E /* Products */; @@ -225,6 +230,7 @@ buildActionMask = 2147483647; files = ( 0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */, + 063C499520E36BF9001BCA35 /* Localizable.strings in Resources */, 0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -338,6 +344,15 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXVariantGroup section */ + 063C499720E36BF9001BCA35 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 063C499620E36BF9001BCA35 /* en */, + 063C499820E36C15001BCA35 /* zh-Hans */, + ); + name = Localizable.strings; + sourceTree = ""; + }; 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -353,6 +368,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -412,6 +428,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; diff --git a/Bark.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Bark.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Bark.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Bark/en.lproj/Localizable.strings b/Bark/en.lproj/Localizable.strings new file mode 100644 index 0000000..b7a53b5 --- /dev/null +++ b/Bark/en.lproj/Localizable.strings @@ -0,0 +1,40 @@ +/* + Localizable.strings + Bark + + Created by huangfeng on 2018/6/27. + Copyright © 2018 Fin. All rights reserved. +*/ + + +SecureConnection = "Secure Connection (HTTPS)"; +InsecureConnection = "Insecure Connection (HTTP)"; +RegisterDevice = "Register Device"; + +CustomedNotifictionContent = "Customed Notifiction Content"; +CustomedNotifictionTitle = "Customed Notifiction Title"; + +Notice1 = "Click on the buttons in the upper right corner \nto copy or preview test URL"; +Notice2 = ""; + +Copy = "Copied!"; + +AllowNotifications = "Notifications have been turned off, Please allow notifications and try again"; + +UnregisteredDevice = "Unregistered Device"; + +ServerError = "Server Error"; + +ServerAddress = "Server Address"; + +ServerExample = "Enter the server address, for example: https://api.day.app"; + +DeploymentDocuments = "Deployment Documentation"; + +AddServer = "Add Customed Server"; + +AddedSuccessfully = "Added Successfully!"; + +InvalidServer = "Invalid server! please try again."; + +InvalidURL = "Invalid URL!"; diff --git a/Bark/zh-Hans.lproj/Localizable.strings b/Bark/zh-Hans.lproj/Localizable.strings new file mode 100644 index 0000000..90d72eb --- /dev/null +++ b/Bark/zh-Hans.lproj/Localizable.strings @@ -0,0 +1,40 @@ +/* + Localizable.strings + Bark + + Created by huangfeng on 2018/6/27. + Copyright © 2018 Fin. All rights reserved. +*/ + + +SecureConnection = "HTTPS安全连接"; +InsecureConnection = "连接不安全,请使用HTTPS安全连接"; +RegisterDevice = "注册设备"; + +CustomedNotifictionContent = "这里改成你自己的推送内容"; +CustomedNotifictionTitle = "推送标题"; + +Notice1 = "点击右上角按钮可以复制测试URL、预览推送效果\nSafari有缓存,没收到推送时请刷新页面"; +Notice2 = "推送标题的字号比推送内容粗一点"; + +Copy = "复制成功"; + +AllowNotifications = "绑定设备需要推送。请打开推送后重试"; + +UnregisteredDevice = "设备未注册,不能使用推送服务"; + +ServerError = "服务器错误,不能使用推送服务"; + +ServerAddress = "服务器地址"; + +ServerExample = "输入服务器地址,例如: https://api.day.app"; + +DeploymentDocuments = "查看服务端部署教程"; + +AddServer = "添加私有服务器"; + +AddedSuccessfully = "修改成功!"; + +InvalidServer = "填写的服务器无效,请重试!"; + +InvalidURL = "输入的URL好像不对劲!"; diff --git a/Controller/HomeViewController.swift b/Controller/HomeViewController.swift index e349174..6678197 100644 --- a/Controller/HomeViewController.swift +++ b/Controller/HomeViewController.swift @@ -17,7 +17,7 @@ class HomeViewController: BaseViewController { return btn }() - let startButton = FABButton(title: "注册设备") + let startButton = FABButton(title: NSLocalizedString("RegisterDevice")) let statusButton = IconButton(image: UIImage(named: "baseline_https_black_24pt"), tintColor: .white) @@ -32,12 +32,12 @@ class HomeViewController: BaseViewController { var dataSource:[PreviewModel] = { return [ PreviewModel( - body:"这里改成你自己的推送内容", - notice: "点击右上角按钮可以复制测试URL、预览推送效果\nSafari有缓存,没收到推送时请刷新页面"), + body: NSLocalizedString("CustomedNotifictionContent"), + notice: NSLocalizedString("Notice1")), PreviewModel( - title: "推送标题", - body:"这里改成你自己的推送内容", - notice: "推送标题的字号比推送内容粗一点") + title: NSLocalizedString("CustomedNotifictionTitle"), + body: NSLocalizedString("CustomedNotifictionContent"), + notice: NSLocalizedString("Notice2")) ] }() @@ -98,7 +98,7 @@ extension HomeViewController : UITableViewDataSource, UITableViewDelegate { let cell = self.tableView.dequeueReusableCell(withIdentifier: "\(PreviewCardCell.self)", for: indexPath) as! PreviewCardCell cell.bind(model: dataSource[indexPath.row]) cell.copyHandler = {[weak self] in - self?.showSnackbar(text: "复制成功") + self?.showSnackbar(text: NSLocalizedString("Copy")) } return cell } @@ -127,7 +127,7 @@ extension HomeViewController { self.startButton.removeFromSuperview() } else{ - self.showSnackbar(text: "绑定设备需要推送。请打开推送后重试") + self.showSnackbar(text: NSLocalizedString("AllowNotifications")) self.startButton.titleColor = Color.blue.base self.startButton.isEnabled = true } @@ -142,19 +142,19 @@ extension HomeViewController { case .ok: if let url = URL(string: ServerManager.shared.currentAddress) { if url.scheme?.lowercased() == "https" { - navigationItem.detailLabel.text = "HTTPS安全连接" + navigationItem.detailLabel.text = NSLocalizedString("SecureConnection") statusButton.image = UIImage(named: "baseline_https_black_24pt") } else { - navigationItem.detailLabel.text = "连接不安全,请使用HTTPS安全连接" + navigationItem.detailLabel.text = NSLocalizedString("InsecureConnection") statusButton.image = UIImage(named: "baseline_http_black_24pt") } self.tableView.reloadData() } case .unRegister: - navigationItem.detailLabel.text = "设备未注册,不能使用推送服务" + navigationItem.detailLabel.text = NSLocalizedString("UnregisteredDevice") case .serverError: - navigationItem.detailLabel.text = "服务器错误,不能使用推送服务" + navigationItem.detailLabel.text = NSLocalizedString("ServerError") } } } diff --git a/Controller/NewServerViewController.swift b/Controller/NewServerViewController.swift index c333bc3..681abdb 100644 --- a/Controller/NewServerViewController.swift +++ b/Controller/NewServerViewController.swift @@ -15,8 +15,8 @@ class NewServerViewController: BaseViewController { let addressTextField : TextField = { let textField = TextField() textField.keyboardType = .URL - textField.placeholder = "服务器地址" - textField.detail = "输入服务器地址,例如: https://api.day.app" + textField.placeholder = NSLocalizedString("ServerAddress") + textField.detail = NSLocalizedString("ServerExample") textField.transition([ .scale(0.85) , .opacity(0)] ) textField.detailLabel.transition([ .scale(0.85) , .opacity(0)] ) return textField @@ -24,7 +24,7 @@ class NewServerViewController: BaseViewController { let noticeLabel: UILabel = { let label = UILabel() - label.text = "查看服务端部署教程" + label.text = NSLocalizedString("DeploymentDocuments") label.textColor = Color.blue.base label.font = UIFont.systemFont(ofSize: 12) label.transition([ .scale(0.85) , .opacity(0), .translate(x: 50)] ) @@ -35,7 +35,7 @@ class NewServerViewController: BaseViewController { override func viewDidLoad() { super.viewDidLoad() - navigationItem.titleLabel.text = "添加私有服务器" + navigationItem.titleLabel.text = NSLocalizedString("AddServer") doneButton.addTarget(self, action: #selector(done), for: .touchUpInside) navigationItem.rightViews = [doneButton] @@ -64,15 +64,15 @@ class NewServerViewController: BaseViewController { .subscribe(onNext: {[weak self] (_) in self?.navigationController?.popViewController(animated: true) ServerManager.shared.currentAddress = text - self?.showSnackbar(text: "修改成功!") + self?.showSnackbar(text: NSLocalizedString("AddedSuccessfully")) Client.shared.bindDeviceToken() }, onError: {[weak self] (error) in - self?.showSnackbar(text: "填写的服务器无效,请重试!\(error.localizedDescription)") + self?.showSnackbar(text: "\(NSLocalizedString("InvalidServer"))\(error.localizedDescription)") }) } else{ - self.showSnackbar(text: "输入的URL好像不对劲!") + self.showSnackbar(text: NSLocalizedString("InvalidURL")) } } diff --git a/Model/Defines.swift b/Model/Defines.swift index 364d6a4..654b8ed 100644 --- a/Model/Defines.swift +++ b/Model/Defines.swift @@ -26,3 +26,7 @@ extension UIViewController { self.snackbarController?.animate(snackbar: .hidden, delay: 3) } } + +func NSLocalizedString( _ key:String ) -> String { + return NSLocalizedString(key, comment: "") +}