-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringsFromXib.swift
71 lines (65 loc) · 3.02 KB
/
StringsFromXib.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// ByvLocalizableStringsGenerator.swift
// ByvLocalizableStringsGenerator
//
// Created by Adrian Apodaca on 2/5/17.
// Copyright © 2017 byvapps. All rights reserved.
//
import Foundation
func stringsFromXibFiles() {
var files = dir?.findFilesRecursively(byExtension: "xib") ?? []
files += dir?.findFilesRecursively(byExtension: "storyboard") ?? []
let dispatchGroup = DispatchGroup()
for file in files {
print("file: \(file.name)")
dispatchGroup.enter()
if let data = file.contents().data(using: .utf8) {
let _ = XML(data: data, searchParams:["locTitles",
"locText",
"locTitle",
"locPlaceholder",
"styledLocText",
"styledLocTitle",
"styledLocPlaceholder"]) { (items) in
for item in items {
if let keyPath = item["keyPath"],
let value = item["value"] {
var string = value.replacingOccurrences(of: "\\", with: "\\\\")
string = string.replacingOccurrences(of: "\"", with: "\\\"")
print("key: \(keyPath)")
print("string: \(string)")
if keyPath == "locTitles" {
//Segmented
let comps = string.components(separatedBy: ";")
for i in 0...comps.count - 1 {
let text = comps[i]
let comment = "Segmented[\(i)]"
var translation = Translation(comment: comment, files: [file.name])
if let storedTranslation = translations[string] {
var storedFiles = storedTranslation.files
storedFiles.append(file.name)
translation.files = storedFiles
}
translations[text] = translation
}
} else {
var translation = Translation(comment: "", files: [file.name])
if let storedTranslation = translations[string] {
var storedFiles = storedTranslation.files
storedFiles.append(file.name)
translation.files = storedFiles
}
translations[string] = translation
}
}
}
dispatchGroup.leave()
}
} else {
print("File: \(file.path) - no data")
dispatchGroup.leave()
}
}
dispatchGroup.wait()
return
}