-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathENInterfaceVariables.swift
More file actions
283 lines (247 loc) · 12.3 KB
/
ENInterfaceVariables.swift
File metadata and controls
283 lines (247 loc) · 12.3 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Constants and functions to load the English Scribe keyboard.
*/
import UIKit
// MARK: Constants
public enum ENKeyboardConstants {
static let defaultCurrencyKey = "$"
static let currencyKeys = ["$", "€", "£", "¥"]
// Alternate key vars.
static let keysWithAlternates = ["a", "e", "i", "o", "u", "y", "c", "l", "n", "s", "z"]
static let keysWithAlternatesLeft = ["a", "e", "y", "c", "s", "z"]
static let keysWithAlternatesRight = ["i", "o", "u", "l", "n"]
static let aAlternateKeys = ["à", "á", "â", "ä", "æ", "ã", "å", "ā"]
static let eAlternateKeys = ["è", "é", "ê", "ë", "ē", "ė", "ę"]
static let iAlternateKeys = ["ì", "į", "ī", "í", "ï", "î"]
static let oAlternateKeys = ["õ", "ō", "ø", "œ", "ó", "ò", "ö", "ô"]
static let uAlternateKeys = ["ū", "ú", "ù", "ü", "û"]
static let cAlternateKeys = ["ç", "ć", "č"]
static let lAlternateKeys = ["ł"]
static let nAlternateKeys = ["ń", "ñ"]
static let sAlternateKeys = ["ś", "š"]
static let zAlternateKeys = ["ž", "ź", "ż"]
}
struct ENKeyboardProvider: KeyboardProviderProtocol {
// MARK: iPhone Layouts
static func genPhoneLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"])
.addRow(["a", "s", "d", "f", "g", "h", "j", "k", "l"])
.addRow(["shift", "z", "x", "c", "v", "b", "n", "m", "delete"])
.addRow(["123", "selectKeyboard", "space", "return"])
.build()
}
static func genPhoneNumberKeys(currencyKey: String) -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"])
.addRow(["-", "/", ":", ";", "(", ")", "$", "&", "@", "\""])
.addRow(["#+=", ".", ",", "?", "!", "'", "delete"])
.addRow(["ABC", "selectKeyboard", "space", "return"])
.replaceKey(row: 1, column: 6, to: currencyKey)
.build()
}
static func genPhoneSymbolKeys(currencyKeys: [String]) -> [[String]] {
let keyboardBuilder = KeyboardBuilder()
.addRow(["[", "]", "{", "}", "#", "%", "^", "*", "+", "="])
.addRow(["_", "\\", "|", "~", "<", ">", "€", "£", "¥", "·"])
.addRow(["123", ".", ",", "?", "!", "'", "delete"])
.addRow(["ABC", "selectKeyboard", "space", "return"])
if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return
keyboardBuilder
.replaceKey(row: 1, column: 6, to: currencyKeys[0])
.replaceKey(row: 1, column: 7, to: currencyKeys[1])
.replaceKey(row: 1, column: 8, to: currencyKeys[2])
.build()
}
}
// MARK: iPad Layouts
static func genPadLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "+"])
.addRow(["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "delete"])
.addRow(["a", "s", "d", "f", "g", "h", "j", "k", "l", "return"])
.addRow(["shift", "w", "x", "c", "v", "b", "n", "m", ",", ".", "shift"])
.addRow(["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"])
.build()
}
static func genPadNumberKeys(currencyKey: String) -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"])
.addRow(["@", "#", "$", "&", "*", "(", ")", "'", "\"", "return"])
.addRow(["#+=", "%", "_", "+", "=", "/", ";", ":", ",", ".", "#+="])
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"])
.replaceKey(row: 1, column: 2, to: currencyKey)
.build()
}
static func genPadSymbolKeys(currencyKeys: [String]) -> [[String]] {
let keyboardBuilder = KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "delete"])
.addRow(["€", "£", "¥", "_", "^", "[", "]", "{", "}", "return"])
.addRow(["123", "§", "|", "~", "...", "\\", "<", ">", "!", "?", "123"])
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"])
if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return
keyboardBuilder
.replaceKey(row: 1, column: 0, to: currencyKeys[0])
.replaceKey(row: 1, column: 1, to: currencyKeys[1])
.replaceKey(row: 1, column: 2, to: currencyKeys[2])
.build()
}
}
static func genPadExpandedLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["~", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "delete"])
.addRow([
SpecialKeys.indent, "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]",
"\\"
])
.addRow([
SpecialKeys.capsLock, "a", "s", "d", "f", "g", "h", "j", "k", "l", ":", ";", "'",
"return"
])
.addRow(["shift", "-", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "shift"])
.addRow(["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"])
.build()
}
static func genPadExpandedSymbolKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">", "delete"])
.addRow([
SpecialKeys.indent, "[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "—", "~", "°"
])
.addRow([
SpecialKeys.capsLock, "-", "\\", ":", ";", "(", ")", "&", "@", "$", "£", "¥", "€",
"return"
])
.addRow(["shift", "…", "?", "!", "≠", "'", "\"", "|", "_", ".", ",", "/", "shift"])
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"])
.build()
}
}
// MARK: Generate and set keyboard
// MARK: Get Keys
func getENKeys() {
guard let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")
else {
fatalError("Unable to access shared user defaults")
}
var currencyKey = ENKeyboardConstants.defaultCurrencyKey
var currencyKeys = ENKeyboardConstants.currencyKeys
let dictionaryKey = controllerLanguage + "defaultCurrencySymbol"
if let currencyValue = userDefaults.string(forKey: dictionaryKey) {
currencyKey = currencyValue
} else {
userDefaults.setValue(currencyKey, forKey: dictionaryKey)
}
if let index = currencyKeys.firstIndex(of: currencyKey) {
currencyKeys.remove(at: index)
}
if DeviceType.isPhone {
letterKeys = ENKeyboardProvider.genPhoneLetterKeys()
numberKeys = ENKeyboardProvider.genPhoneNumberKeys(currencyKey: currencyKey)
symbolKeys = ENKeyboardProvider.genPhoneSymbolKeys(currencyKeys: currencyKeys)
allKeys =
Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
} else {
// Use the expanded keys layout if the iPad is wide enough and has no home button.
if usingExpandedKeyboard {
letterKeys = ENKeyboardProvider.genPadExpandedLetterKeys()
symbolKeys = ENKeyboardProvider.genPadExpandedSymbolKeys()
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
} else {
letterKeys = ENKeyboardProvider.genPadLetterKeys()
numberKeys = ENKeyboardProvider.genPadNumberKeys(currencyKey: currencyKey)
symbolKeys = ENKeyboardProvider.genPadSymbolKeys(currencyKeys: currencyKeys)
letterKeys.removeFirst(1)
allKeys =
Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
}
}
keysWithAlternates = ENKeyboardConstants.keysWithAlternates
keysWithAlternatesLeft = ENKeyboardConstants.keysWithAlternatesLeft
keysWithAlternatesRight = ENKeyboardConstants.keysWithAlternatesRight
aAlternateKeys = ENKeyboardConstants.aAlternateKeys
eAlternateKeys = ENKeyboardConstants.eAlternateKeys
iAlternateKeys = ENKeyboardConstants.iAlternateKeys
oAlternateKeys = ENKeyboardConstants.oAlternateKeys
uAlternateKeys = ENKeyboardConstants.uAlternateKeys
sAlternateKeys = ENKeyboardConstants.sAlternateKeys
lAlternateKeys = ENKeyboardConstants.lAlternateKeys
zAlternateKeys = ENKeyboardConstants.zAlternateKeys
cAlternateKeys = ENKeyboardConstants.cAlternateKeys
nAlternateKeys = ENKeyboardConstants.nAlternateKeys
}
// MARK: Provide Layout
func setENKeyboardLayout() {
getENKeys()
currencySymbol = "$"
currencySymbolAlternates = dollarAlternateKeys
spaceBar = "space"
invalidCommandMsgWikidata = "Not in Wikidata"
invalidCommandTextWikidata1 =
"Wikidata is a collaboratively edited knowledge graph that's maintained by the Wikimedia Foundation. It serves as a source of open data for projects like Wikipedia and countless others."
invalidCommandTextWikidata2 =
"Scribe uses Wikidata's language data for many of its core features. We get information like noun genders, verb conjugations and much more!"
invalidCommandTextWikidata3 =
"You can make an account at wikidata.org to join the community that's supporting Scribe and so many other projects. Help us bring free information to the world!"
invalidCommandMsgWiktionary = "Not in Wiktionary"
invalidCommandTextWiktionary1 =
"Wiktionary is a collaboratively edited dictionary that's maintained by the Wikimedia Foundation. It serves as a source of free linguistic data for projects like Wikipedia and countless others."
invalidCommandTextWiktionary2 =
"Scribe uses Wiktionary's data to provide translations for its Translate command. Our data is derived from the many language pairs that Wiktionary's community has created!"
invalidCommandTextWiktionary3 =
"You can make an account at wiktionary.org to join the community that's supporting Scribe and so many other projects. Help us bring free information to the world!"
baseAutosuggestions = ["I", "I'm", "we"]
numericAutosuggestions = ["is", "to", "and"]
verbsAfterPronounsArray = ["have", "be", "can"]
pronounAutosuggestionTenses = [
"I": "presSimp",
"you": "presSimp",
"he": "presTPS",
"she": "presTPS",
"it": "presTPS",
"we": "presSimp",
"they": "presSimp"
]
translateKeyLbl = "Translate"
translatePlaceholder = "Enter a word"
translatePrompt = commandPromptSpacing + "en -› \(getControllerLanguageAbbr()): "
translatePromptAndCursor = translatePrompt + commandCursor
translatePromptAndPlaceholder = translatePromptAndCursor + " " + translatePlaceholder
translatePromptAndColorPlaceholder = NSMutableAttributedString(
string: translatePromptAndPlaceholder
)
translatePromptAndColorPlaceholder.setColorForText(
textForAttribute: translatePlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
conjugateKeyLbl = "Conjugate"
conjugatePlaceholder = "Enter a verb"
conjugatePrompt = commandPromptSpacing + "Conjugate: "
conjugatePromptAndCursor = conjugatePrompt + commandCursor
conjugatePromptAndPlaceholder = conjugatePromptAndCursor + " " + conjugatePlaceholder
conjugatePromptAndColorPlaceholder = NSMutableAttributedString(
string: conjugatePromptAndPlaceholder
)
conjugatePromptAndColorPlaceholder.setColorForText(
textForAttribute: conjugatePlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
pluralKeyLbl = "Plural"
pluralPlaceholder = "Enter a noun"
pluralPrompt = commandPromptSpacing + "Plural: "
pluralPromptAndCursor = pluralPrompt + commandCursor
pluralPromptAndPlaceholder = pluralPromptAndCursor + " " + pluralPlaceholder
pluralPromptAndColorPlaceholder = NSMutableAttributedString(string: pluralPromptAndPlaceholder)
pluralPromptAndColorPlaceholder.setColorForText(
textForAttribute: pluralPlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
alreadyPluralMsg = "Already plural"
}