-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringsFilesCreator.swift
More file actions
61 lines (49 loc) · 1.97 KB
/
Copy pathStringsFilesCreator.swift
File metadata and controls
61 lines (49 loc) · 1.97 KB
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
//
// ByvLocalizableStringsGenerator.swift
// ByvLocalizableStringsGenerator
//
// Created by Adrian Apodaca on 3/5/18.
// Copyright © 2017 byvapps. All rights reserved.
//
import Foundation
func generateStringsFiles(translations: [String:Translation]) {
let languages = Language.allLanguages()
let stringsFilePath = path + "/all.strings"
// create new strings file
_ = shell(
launchPath: "/usr/bin/env",
arguments: [
"touch",
"\(stringsFilePath)"
]
)
guard let stringsFileHandle = FileHandle(forWritingAtPath: stringsFilePath) else {
print("no file to write to \(stringsFilePath) was not created or available")
abort()
}
for text in translations.keys {
let newline = "\r\n"
if let translation = translations[text] {
let rule = "\(newline)/* Files = \(translation.files); comment = \"\(translation.comment)\" */\(newline)\"\(text)\" = \"\(text)\";\(newline)"
stringsFileHandle.write(rule.data(using: .utf8)!)
//Stored Languages
let emptyRule = "\(newline)/* Files = \(translation.files); comment = \"\(text)\" */\(newline)\"\(text)\" = \"\";\(newline)"
for language in languages {
if language.translated[text] == nil {
//Translation not stored
if language.langId.uppercased() == "BASE" {
language.stringsFileHandle?.write(rule.data(using: .utf8)!)
} else {
language.stringsFileHandle?.write(emptyRule.data(using: .utf8)!)
}
}
}
}
}
print("Outputted base.strings file in \(stringsFilePath)")
stringsFileHandle.closeFile()
for language in languages {
print("Outputted base.strings file in \(language.newPath)")
language.stringsFileHandle?.closeFile()
}
}