-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage.swift
59 lines (51 loc) · 1.58 KB
/
Language.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
//
// ByvLocalizableStringsGenerator.swift
// ByvLocalizableStringsGenerator
//
// Created by Adrian Apodaca on 3/5/18.
// Copyright © 2017 byvapps. All rights reserved.
//
import Foundation
class Language {
let langId:String
var translated:[String:String] = [:]
let newPath:String
let stringsFileHandle:FileHandle?
init(file: File) {
var lang = "base"
for comp in file.path.components(separatedBy: "/") {
let comps = comp.components(separatedBy: ".lproj")
if comps[0] != comp {
lang = comps[0]
print("Language: \(lang)")
break
}
}
self.langId = lang
do {
let text = try String(contentsOfFile: file.path)
self.translated = text.propertyListFromStringsFileFormat()
} catch {
self.translated = [:]
}
newPath = path + "/\(self.langId).strings"
_ = shell(
launchPath: "/usr/bin/env",
arguments: [
"touch",
"\(newPath)"
])
self.stringsFileHandle = FileHandle(forWritingAtPath: newPath)
}
static func allLanguages() -> [Language] {
guard let lacalizables = dir?.findFilesRecursively(byName: "Localizable.strings") else {
abort()
}
var response:[Language] = []
for file in lacalizables {
print("Localizable: \(file.path)")
response.append(Language(file: file))
}
return response
}
}