Skip to content

Commit 42426a9

Browse files
author
josercc
committed
新增操作判断提示和完善了ReadMe
1 parent 13f4353 commit 42426a9

16 files changed

Lines changed: 134 additions & 34 deletions

2018-07-27 11_38_14.gif

47.6 MB
Loading

LocalizedCSV/LocalizedCSV.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
5D505E8E1F5E9EE400016766 /* LanguageSourceKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D505E8D1F5E9EE400016766 /* LanguageSourceKit.swift */; };
2525
5D84B93A1F4A851E009EA4A2 /* FileKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D84B9391F4A851E009EA4A2 /* FileKit.swift */; };
2626
5DA04CF421096C0B00770A2B /* LanguageFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA04CF321096C0B00770A2B /* LanguageFunction.swift */; };
27+
5DA04CF6210AAE2C00770A2B /* CheckConfigManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DA04CF5210AAE2C00770A2B /* CheckConfigManager.swift */; };
2728
5DE617E51FA1CA85000A6370 /* SettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DE617E41FA1CA85000A6370 /* SettingViewController.swift */; };
2829
9B82C449E090FFB5A46E370C /* Pods_LocalizedCSV.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F0EA87C987B058659C431A /* Pods_LocalizedCSV.framework */; };
2930
/* End PBXBuildFile section */
@@ -49,6 +50,7 @@
4950
5D505E8D1F5E9EE400016766 /* LanguageSourceKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LanguageSourceKit.swift; sourceTree = "<group>"; };
5051
5D84B9391F4A851E009EA4A2 /* FileKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileKit.swift; sourceTree = "<group>"; };
5152
5DA04CF321096C0B00770A2B /* LanguageFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageFunction.swift; sourceTree = "<group>"; };
53+
5DA04CF5210AAE2C00770A2B /* CheckConfigManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckConfigManager.swift; sourceTree = "<group>"; };
5254
5DE617E41FA1CA85000A6370 /* SettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingViewController.swift; sourceTree = "<group>"; };
5355
78AB411939E0316119BB7FDD /* Pods-LocalizedCSV.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LocalizedCSV.release.xcconfig"; path = "Pods/Target Support Files/Pods-LocalizedCSV/Pods-LocalizedCSV.release.xcconfig"; sourceTree = "<group>"; };
5456
9CA2E9213676361ECC6388E9 /* Pods-LocalizedCSV.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LocalizedCSV.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LocalizedCSV/Pods-LocalizedCSV.debug.xcconfig"; sourceTree = "<group>"; };
@@ -115,6 +117,7 @@
115117
5DE617E41FA1CA85000A6370 /* SettingViewController.swift */,
116118
5D005DF01FA2D9650085E94C /* TranslateStringViewController.swift */,
117119
5DA04CF321096C0B00770A2B /* LanguageFunction.swift */,
120+
5DA04CF5210AAE2C00770A2B /* CheckConfigManager.swift */,
118121
);
119122
path = LocalizedCSV;
120123
sourceTree = "<group>";
@@ -258,6 +261,7 @@
258261
5DE617E51FA1CA85000A6370 /* SettingViewController.swift in Sources */,
259262
5D499EF21F469939000F24B1 /* LanguageValueController.swift in Sources */,
260263
5D2D67C01F484F95002761E4 /* StringKit.swift in Sources */,
264+
5DA04CF6210AAE2C00770A2B /* CheckConfigManager.swift in Sources */,
261265
5D499EF81F47D611000F24B1 /* FindLocalizeStringController.swift in Sources */,
262266
5D499EFC1F48252D000F24B1 /* FilndUnLocalizeStringKit.swift in Sources */,
263267
5D499EF41F46AD5E000F24B1 /* LocalizeStringKit.swift in Sources */,
@@ -384,6 +388,7 @@
384388
DEVELOPMENT_TEAM = UL78A6B4GH;
385389
INFOPLIST_FILE = LocalizedCSV/Info.plist;
386390
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
391+
MACOSX_DEPLOYMENT_TARGET = 10.10;
387392
PRODUCT_BUNDLE_IDENTIFIER = com.zhanghang.LocalizedCSV;
388393
PRODUCT_NAME = "$(TARGET_NAME)";
389394
SWIFT_VERSION = 3.0;
@@ -399,6 +404,7 @@
399404
DEVELOPMENT_TEAM = UL78A6B4GH;
400405
INFOPLIST_FILE = LocalizedCSV/Info.plist;
401406
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
407+
MACOSX_DEPLOYMENT_TARGET = 10.10;
402408
PRODUCT_BUNDLE_IDENTIFIER = com.zhanghang.LocalizedCSV;
403409
PRODUCT_NAME = "$(TARGET_NAME)";
404410
SWIFT_VERSION = 3.0;

LocalizedCSV/LocalizedCSV/AppDelegate.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
2222
///
2323
/// - Parameter sender: 执行的按钮
2424
@IBAction func findProjLocalizeString(_ sender: Any) {
25+
findProjLocalizeString()
26+
}
27+
28+
func findProjLocalizeString() {
2529
guard let path = FileKit.getDirectory() else {
2630
return
2731
}

LocalizedCSV/LocalizedCSV/Base.lproj/Main.storyboard

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!--设置-->
1010
<scene sceneID="6sj-Lf-SRK">
1111
<objects>
12-
<viewController title="设置" id="2MZ-1w-cLK" customClass="SettingViewController" customModule="LocalizedCSV" customModuleProvider="target" sceneMemberID="viewController">
12+
<viewController title="设置" identifier="SettingViewController" storyboardIdentifier="SettingViewController" id="2MZ-1w-cLK" customClass="SettingViewController" customModule="LocalizedCSV" customModuleProvider="target" sceneMemberID="viewController">
1313
<view key="view" id="NVG-AN-y6c">
1414
<rect key="frame" x="0.0" y="0.0" width="466" height="300"/>
1515
<autoresizingMask key="autoresizingMask"/>
@@ -78,6 +78,9 @@
7878
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
7979
<font key="font" size="13" name=".PingFangSC-Regular"/>
8080
</buttonCell>
81+
<connections>
82+
<action selector="setting:" target="2MZ-1w-cLK" id="4z3-tX-lQx"/>
83+
</connections>
8184
</button>
8285
</subviews>
8386
<constraints>
@@ -99,6 +102,7 @@
99102
</view>
100103
<connections>
101104
<outlet property="languageCodeTextView" destination="P5w-qh-Anp" id="elN-oh-wG4"/>
105+
<outlet property="searchLocalizetionPrefix" destination="G8u-VF-iF4" id="6Db-hd-Se3"/>
102106
</connections>
103107
</viewController>
104108
<customObject id="VGM-wQ-PGK" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
@@ -791,6 +795,7 @@
791795
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
792796
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
793797
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
798+
<value key="minSize" type="size" width="600" height="400"/>
794799
<connections>
795800
<outlet property="delegate" destination="B8D-0N-5wS" id="9A6-Qi-XQM"/>
796801
</connections>
@@ -971,16 +976,16 @@
971976
<autoresizingMask key="autoresizingMask"/>
972977
<subviews>
973978
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="tJh-nT-MNd">
974-
<rect key="frame" x="10" y="395" width="363" height="22"/>
979+
<rect key="frame" x="10" y="395" width="364" height="22"/>
975980
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="输入SVG路径" drawsBackground="YES" id="ZDF-iD-wBf">
976981
<font key="font" metaFont="system"/>
977982
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
978983
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
979984
</textFieldCell>
980985
</textField>
981986
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FDh-aF-YHm">
982-
<rect key="frame" x="397" y="388" width="121" height="32"/>
983-
<buttonCell key="cell" type="push" title="选取SVG文件" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="JFU-np-hSZ">
987+
<rect key="frame" x="398" y="388" width="120" height="32"/>
988+
<buttonCell key="cell" type="push" title="选取CSV文件" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="JFU-np-hSZ">
984989
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
985990
<font key="font" size="13" name=".PingFangSC-Regular"/>
986991
</buttonCell>
@@ -989,8 +994,8 @@
989994
</connections>
990995
</button>
991996
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="L9B-IA-cIA">
992-
<rect key="frame" x="335" y="343" width="183" height="32"/>
993-
<buttonCell key="cell" type="push" title="选取LocalizeString文件" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fEx-Il-PEJ">
997+
<rect key="frame" x="282" y="343" width="236" height="32"/>
998+
<buttonCell key="cell" type="push" title="选取LocalizeString开发语言文件" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="fEx-Il-PEJ">
994999
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
9951000
<font key="font" size="13" name=".PingFangSC-Regular"/>
9961001
</buttonCell>
@@ -999,7 +1004,7 @@
9991004
</connections>
10001005
</button>
10011006
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Gdb-Y4-jBc">
1002-
<rect key="frame" x="10" y="350" width="301" height="22"/>
1007+
<rect key="frame" x="10" y="350" width="248" height="22"/>
10031008
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" placeholderString="输入LocazeString文件路径" drawsBackground="YES" id="YDu-b1-qdm">
10041009
<font key="font" metaFont="system"/>
10051010
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// CheckConfigManager.swift
3+
// LocalizedCSV
4+
//
5+
// Created by 张行 on 2018/7/27.
6+
// Copyright © 2018年 张行. All rights reserved.
7+
//
8+
9+
import AppKit
10+
11+
/*
12+
俄语-Русский язык:ru
13+
匈牙利语-Hungarian:hu
14+
阿拉伯语-اللغة العربية:ar
15+
葡萄牙葡萄牙语-Português-:pt-PT
16+
印尼-indonesian:id
17+
波兰—Polski:pl
18+
土耳其-Türkçe:tr
19+
西语-español:es
20+
法语-french:fr
21+
以色列(希伯来语)-Hebrew:he-IL
22+
意大利-Italiano:it
23+
希腊-greece:el
24+
巴葡-português brasileiro:pt-BR
25+
德语-Deutsch:de
26+
荷兰语-dutch:nl
27+
*/
28+
/* 检查配置 */
29+
class CheckConfigManager {
30+
/* 检查的工程是否配置好 */
31+
static func checkConfigReadySuccess() -> Bool {
32+
/* 先检车配置 */
33+
guard SettingModel.shareSettingModel().projectLanguageCode.count > 0 else {
34+
let alert = NSAlert()
35+
alert.messageText = "检测你还没有配置多语言简码,无法继续操作,请进行配置。"
36+
let response = alert.runModal()
37+
if response == NSFileHandlingPanelCancelButton {
38+
if let settingController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "SettingViewController") as? SettingViewController {
39+
let window = NSWindow(contentViewController: settingController)
40+
let windowController = NSWindowController(window: window)
41+
windowController.showWindow(nil)
42+
}
43+
44+
}
45+
return false
46+
}
47+
guard FindLocalizeStringKit.shareManager().list.count > 0 else {
48+
let alert = NSAlert()
49+
alert.messageText = "检测你还没有读取工程多语言,无法继续操作,请进行读取。"
50+
let response = alert.runModal()
51+
if response == NSFileHandlingPanelCancelButton {
52+
if let appDelegate = NSApp.delegate as? AppDelegate {
53+
appDelegate.findProjLocalizeString()
54+
}
55+
}
56+
return false
57+
}
58+
return true
59+
}
60+
}

LocalizedCSV/LocalizedCSV/FindLocalizeStringKit.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class FindLocalizeStringKit {
8585
/* 存放查找出来的多语言字典 */
8686
var localizeString:[String:String] = [:]
8787
/* 查找出现第一个所在的位置GBLocalizedString( */
88-
guard let range1 = string.range(of: "GBLocalizedString(") else {
88+
let searchLocallizetionPrefix = SettingModel.shareSettingModel().searchLocalizetionPrefix ?? "GBLocalizedString"
89+
guard let range1 = string.range(of: "\(searchLocallizetionPrefix)(") else {
8990
/* 查找不到就返回 */
9091
return localizeString
9192
}

LocalizedCSV/LocalizedCSV/SettingViewController.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Cocoa
1111
class SettingViewController: NSViewController {
1212

1313
@IBOutlet weak var languageCodeTextView:NSTextView!
14-
14+
@IBOutlet weak var searchLocalizetionPrefix:NSTextField!
1515
override func viewDidLoad() {
1616
super.viewDidLoad()
1717
self.languageCodeTextView.string = SettingModel.shareSettingModel().languageCodeString()
@@ -33,6 +33,9 @@ class SettingViewController: NSViewController {
3333
SettingModel.shareSettingModel().saveNewLanguageCode(dic: textDic)
3434
}
3535

36+
@IBAction func setting(_ sender: Any) {
37+
SettingModel.shareSettingModel().searchLocalizetionPrefix = self.searchLocalizetionPrefix.stringValue
38+
}
3639
}
3740

3841
let settingModel = SettingModel()
@@ -42,6 +45,8 @@ class SettingModel {
4245
var projectRootPath:String?
4346

4447
var projectLanguageCode:[String:String] = [:]
48+
49+
var searchLocalizetionPrefix:String?
4550

4651
init() {
4752
if let oldLanguageCode = UserDefaults.standard.object(forKey: "projectLanguageCode") as? [String:String] {
@@ -54,9 +59,7 @@ class SettingModel {
5459
}
5560

5661
func saveNewLanguageCode(dic:[String:String]) {
57-
for (key,value) in dic {
58-
self.projectLanguageCode[key] = value
59-
}
62+
self.projectLanguageCode = dic
6063
UserDefaults.standard.set(self.projectLanguageCode, forKey: "projectLanguageCode")
6164
UserDefaults.standard.synchronize()
6265
}

LocalizedCSV/LocalizedCSV/ViewController.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
3333
}
3434

3535
@IBAction func readCSVFile(_ sender: NSButton) {
36+
guard CheckConfigManager.checkConfigReadySuccess() else {
37+
return
38+
}
3639
/* 读取 CSV 文件并赋值到文本框里面 */
3740
self.csvTextFiled.stringValue = FileKit.getFile(fileType: "csv")
3841
/* 执行异步解析 */
@@ -69,6 +72,9 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
6972
}
7073

7174
@IBAction func readLocalizeStringFile(_ sender: NSButton) {
75+
guard CheckConfigManager.checkConfigReadySuccess() else {
76+
return
77+
}
7278
self.localizeStringTextFiled.stringValue = FileKit.getFile(fileType: "strings")
7379
try? LocalizeStringKit.shareManager().parse(filePath: self.localizeStringTextFiled.stringValue)
7480
var stringList = self.localizeStringTextFiled.stringValue.components(separatedBy: "/")
@@ -117,6 +123,9 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
117123
拿着本地工程的所有 Key 对比多语言表格的 Key 如果不在多语言表格里面 则代表需要添加的
118124
*/
119125
@IBAction func exportUnAdd(_ sender: Any) {
126+
guard CheckConfigManager.checkConfigReadySuccess() else {
127+
return
128+
}
120129
/* 获取全部的多语言配置列表 */
121130
let list = FindLocalizeStringKit.shareManager().list
122131
guard list.count > 0 else {
@@ -220,6 +229,9 @@ class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelega
220229

221230
/* 一键快速保存所有的多语言 */
222231
@IBAction func quickAllLocalizetion(_ sender: Any) {
232+
guard CheckConfigManager.checkConfigReadySuccess() else {
233+
return
234+
}
223235
var errorMessage = ""
224236
guard let rootPath = SettingModel.shareSettingModel().projectRootPath else {
225237
let alert = NSAlert()

0 commit comments

Comments
 (0)