本地化

This commit is contained in:
Fin 2018-06-28 15:02:24 +08:00
parent 216814ee4f
commit 9481d5a009
7 changed files with 128 additions and 19 deletions

View File

@ -21,6 +21,7 @@
0637FA8620E0AB6600E80174 /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8520E0AB6600E80174 /* UIColor+Extension.swift */; }; 0637FA8620E0AB6600E80174 /* UIColor+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8520E0AB6600E80174 /* UIColor+Extension.swift */; };
0637FA8A20E0D58800E80174 /* NewServerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8920E0D58800E80174 /* NewServerViewController.swift */; }; 0637FA8A20E0D58800E80174 /* NewServerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8920E0D58800E80174 /* NewServerViewController.swift */; };
0637FA8C20E0D7A700E80174 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0637FA8B20E0D7A700E80174 /* BaseViewController.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 */; }; 0661A543204FDA4100965E4E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0661A542204FDA4100965E4E /* AppDelegate.swift */; };
0661A545204FDA4100965E4E /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0661A544204FDA4100965E4E /* HomeViewController.swift */; }; 0661A545204FDA4100965E4E /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0661A544204FDA4100965E4E /* HomeViewController.swift */; };
0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; }; 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 = "<group>"; }; 0637FA8520E0AB6600E80174 /* UIColor+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extension.swift"; sourceTree = "<group>"; };
0637FA8920E0D58800E80174 /* NewServerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewServerViewController.swift; sourceTree = "<group>"; }; 0637FA8920E0D58800E80174 /* NewServerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewServerViewController.swift; sourceTree = "<group>"; };
0637FA8B20E0D7A700E80174 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; }; 0637FA8B20E0D7A700E80174 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
063C499620E36BF9001BCA35 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
063C499820E36C15001BCA35 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
0661A53F204FDA4100965E4E /* Bark.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bark.app; sourceTree = BUILT_PRODUCTS_DIR; }; 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 = "<group>"; }; 0661A542204FDA4100965E4E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
0661A544204FDA4100965E4E /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; }; 0661A544204FDA4100965E4E /* HomeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewController.swift; sourceTree = "<group>"; };
@ -134,6 +137,7 @@
0661A549204FDA4100965E4E /* Assets.xcassets */, 0661A549204FDA4100965E4E /* Assets.xcassets */,
0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */, 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */,
0661A54E204FDA4100965E4E /* Info.plist */, 0661A54E204FDA4100965E4E /* Info.plist */,
063C499720E36BF9001BCA35 /* Localizable.strings */,
); );
path = Bark; path = Bark;
sourceTree = "<group>"; sourceTree = "<group>";
@ -208,6 +212,7 @@
knownRegions = ( knownRegions = (
en, en,
Base, Base,
"zh-Hans",
); );
mainGroup = 0661A536204FDA4100965E4E; mainGroup = 0661A536204FDA4100965E4E;
productRefGroup = 0661A540204FDA4100965E4E /* Products */; productRefGroup = 0661A540204FDA4100965E4E /* Products */;
@ -225,6 +230,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */, 0661A54D204FDA4100965E4E /* LaunchScreen.storyboard in Resources */,
063C499520E36BF9001BCA35 /* Localizable.strings in Resources */,
0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */, 0661A54A204FDA4100965E4E /* Assets.xcassets in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -338,6 +344,15 @@
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */ /* Begin PBXVariantGroup section */
063C499720E36BF9001BCA35 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
063C499620E36BF9001BCA35 /* en */,
063C499820E36C15001BCA35 /* zh-Hans */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */ = { 0661A54B204FDA4100965E4E /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup; isa = PBXVariantGroup;
children = ( children = (
@ -353,6 +368,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
@ -412,6 +428,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

View File

@ -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!";

View File

@ -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好像不对劲!";

View File

@ -17,7 +17,7 @@ class HomeViewController: BaseViewController {
return btn return btn
}() }()
let startButton = FABButton(title: "注册设备") let startButton = FABButton(title: NSLocalizedString("RegisterDevice"))
let statusButton = IconButton(image: UIImage(named: "baseline_https_black_24pt"), tintColor: .white) let statusButton = IconButton(image: UIImage(named: "baseline_https_black_24pt"), tintColor: .white)
@ -32,12 +32,12 @@ class HomeViewController: BaseViewController {
var dataSource:[PreviewModel] = { var dataSource:[PreviewModel] = {
return [ return [
PreviewModel( PreviewModel(
body:"这里改成你自己的推送内容", body: NSLocalizedString("CustomedNotifictionContent"),
notice: "点击右上角按钮可以复制测试URL、预览推送效果\nSafari有缓存没收到推送时请刷新页面"), notice: NSLocalizedString("Notice1")),
PreviewModel( PreviewModel(
title: "推送标题", title: NSLocalizedString("CustomedNotifictionTitle"),
body:"这里改成你自己的推送内容", body: NSLocalizedString("CustomedNotifictionContent"),
notice: "推送标题的字号比推送内容粗一点") notice: NSLocalizedString("Notice2"))
] ]
}() }()
@ -98,7 +98,7 @@ extension HomeViewController : UITableViewDataSource, UITableViewDelegate {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "\(PreviewCardCell.self)", for: indexPath) as! PreviewCardCell let cell = self.tableView.dequeueReusableCell(withIdentifier: "\(PreviewCardCell.self)", for: indexPath) as! PreviewCardCell
cell.bind(model: dataSource[indexPath.row]) cell.bind(model: dataSource[indexPath.row])
cell.copyHandler = {[weak self] in cell.copyHandler = {[weak self] in
self?.showSnackbar(text: "复制成功") self?.showSnackbar(text: NSLocalizedString("Copy"))
} }
return cell return cell
} }
@ -127,7 +127,7 @@ extension HomeViewController {
self.startButton.removeFromSuperview() self.startButton.removeFromSuperview()
} }
else{ else{
self.showSnackbar(text: "绑定设备需要推送。请打开推送后重试") self.showSnackbar(text: NSLocalizedString("AllowNotifications"))
self.startButton.titleColor = Color.blue.base self.startButton.titleColor = Color.blue.base
self.startButton.isEnabled = true self.startButton.isEnabled = true
} }
@ -142,19 +142,19 @@ extension HomeViewController {
case .ok: case .ok:
if let url = URL(string: ServerManager.shared.currentAddress) { if let url = URL(string: ServerManager.shared.currentAddress) {
if url.scheme?.lowercased() == "https" { if url.scheme?.lowercased() == "https" {
navigationItem.detailLabel.text = "HTTPS安全连接" navigationItem.detailLabel.text = NSLocalizedString("SecureConnection")
statusButton.image = UIImage(named: "baseline_https_black_24pt") statusButton.image = UIImage(named: "baseline_https_black_24pt")
} }
else { else {
navigationItem.detailLabel.text = "连接不安全请使用HTTPS安全连接" navigationItem.detailLabel.text = NSLocalizedString("InsecureConnection")
statusButton.image = UIImage(named: "baseline_http_black_24pt") statusButton.image = UIImage(named: "baseline_http_black_24pt")
} }
self.tableView.reloadData() self.tableView.reloadData()
} }
case .unRegister: case .unRegister:
navigationItem.detailLabel.text = "设备未注册,不能使用推送服务" navigationItem.detailLabel.text = NSLocalizedString("UnregisteredDevice")
case .serverError: case .serverError:
navigationItem.detailLabel.text = "服务器错误,不能使用推送服务" navigationItem.detailLabel.text = NSLocalizedString("ServerError")
} }
} }
} }

View File

@ -15,8 +15,8 @@ class NewServerViewController: BaseViewController {
let addressTextField : TextField = { let addressTextField : TextField = {
let textField = TextField() let textField = TextField()
textField.keyboardType = .URL textField.keyboardType = .URL
textField.placeholder = "服务器地址" textField.placeholder = NSLocalizedString("ServerAddress")
textField.detail = "输入服务器地址,例如: https://api.day.app" textField.detail = NSLocalizedString("ServerExample")
textField.transition([ .scale(0.85) , .opacity(0)] ) textField.transition([ .scale(0.85) , .opacity(0)] )
textField.detailLabel.transition([ .scale(0.85) , .opacity(0)] ) textField.detailLabel.transition([ .scale(0.85) , .opacity(0)] )
return textField return textField
@ -24,7 +24,7 @@ class NewServerViewController: BaseViewController {
let noticeLabel: UILabel = { let noticeLabel: UILabel = {
let label = UILabel() let label = UILabel()
label.text = "查看服务端部署教程" label.text = NSLocalizedString("DeploymentDocuments")
label.textColor = Color.blue.base label.textColor = Color.blue.base
label.font = UIFont.systemFont(ofSize: 12) label.font = UIFont.systemFont(ofSize: 12)
label.transition([ .scale(0.85) , .opacity(0), .translate(x: 50)] ) label.transition([ .scale(0.85) , .opacity(0), .translate(x: 50)] )
@ -35,7 +35,7 @@ class NewServerViewController: BaseViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
navigationItem.titleLabel.text = "添加私有服务器" navigationItem.titleLabel.text = NSLocalizedString("AddServer")
doneButton.addTarget(self, action: #selector(done), for: .touchUpInside) doneButton.addTarget(self, action: #selector(done), for: .touchUpInside)
navigationItem.rightViews = [doneButton] navigationItem.rightViews = [doneButton]
@ -64,15 +64,15 @@ class NewServerViewController: BaseViewController {
.subscribe(onNext: {[weak self] (_) in .subscribe(onNext: {[weak self] (_) in
self?.navigationController?.popViewController(animated: true) self?.navigationController?.popViewController(animated: true)
ServerManager.shared.currentAddress = text ServerManager.shared.currentAddress = text
self?.showSnackbar(text: "修改成功!") self?.showSnackbar(text: NSLocalizedString("AddedSuccessfully"))
Client.shared.bindDeviceToken() Client.shared.bindDeviceToken()
}, onError: {[weak self] (error) in }, onError: {[weak self] (error) in
self?.showSnackbar(text: "填写的服务器无效,请重试!\(error.localizedDescription)") self?.showSnackbar(text: "\(NSLocalizedString("InvalidServer"))\(error.localizedDescription)")
}) })
} }
else{ else{
self.showSnackbar(text: "输入的URL好像不对劲!") self.showSnackbar(text: NSLocalizedString("InvalidURL"))
} }
} }

View File

@ -26,3 +26,7 @@ extension UIViewController {
self.snackbarController?.animate(snackbar: .hidden, delay: 3) self.snackbarController?.animate(snackbar: .hidden, delay: 3)
} }
} }
func NSLocalizedString( _ key:String ) -> String {
return NSLocalizedString(key, comment: "")
}