-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathITInterfaceVariables.swift
More file actions
270 lines (234 loc) · 12 KB
/
ITInterfaceVariables.swift
File metadata and controls
270 lines (234 loc) · 12 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
// SPDX-License-Identifier: GPL-3.0-or-later
/*
* Constants and functions to load the Italian Scribe keyboard.
*/
import UIKit
// MARK: Constants
public enum ITKeyboardConstants {
static let defaultCurrencyKey = "€"
static let currencyKeys = ["€", "$", "£", "¥"]
// Alternate key vars.
static let keysWithAlternates = ["a", "e", "i", "o", "u", "c", "n", "s"]
static let keysWithAlternatesLeft = ["a", "e", "s", "c"]
static let keysWithAlternatesRight = ["i", "o", "u", "n"]
static let aAlternateKeys = ["à", "á", "ä", "â", "æ", "ã", "å", "ā", "ᵃ"]
static let eAlternateKeys = ["é", "è", "ə", "ê", "ë", "ę", "ė", "ē"]
static let iAlternateKeys = ["ī", "į", "ï", "î", "í", "ì"]
static let oAlternateKeys = ["ᵒ", "ō", "ø", "œ", "õ", "ö", "ô", "ó", "ò"]
static let uAlternateKeys = ["ū", "ü", "û", "ú", "ù"]
static let cAlternateKeys = ["ç", "ć", "č"]
static let nAlternateKeys = ["ñ"]
static let sAlternateKeys = ["ß", "ś", "š"]
}
struct ITKeyboardProvider: 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", "z", "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()
}
}
// MARK: Expanded iPad Layouts
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"]) // "shift"
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"])
.build()
}
}
// MARK: Get Keys
func getITKeys() {
guard let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")
else {
fatalError("Unable to access shared user defaults")
}
var currencyKey = ITKeyboardConstants.defaultCurrencyKey
var currencyKeys = ITKeyboardConstants.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 = ITKeyboardProvider.genPhoneLetterKeys()
numberKeys = ITKeyboardProvider.genPhoneNumberKeys(currencyKey: currencyKey)
symbolKeys = ITKeyboardProvider.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 = ITKeyboardProvider.genPadExpandedLetterKeys()
symbolKeys = ITKeyboardProvider.genPadExpandedSymbolKeys()
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
} else {
letterKeys = ITKeyboardProvider.genPadLetterKeys()
numberKeys = ITKeyboardProvider.genPadNumberKeys(currencyKey: currencyKey)
symbolKeys = ITKeyboardProvider.genPadSymbolKeys(currencyKeys: currencyKeys)
letterKeys.removeFirst(1)
allKeys =
Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
}
}
keysWithAlternates = ITKeyboardConstants.keysWithAlternates
keysWithAlternatesLeft = ITKeyboardConstants.keysWithAlternatesLeft
keysWithAlternatesRight = ITKeyboardConstants.keysWithAlternatesRight
aAlternateKeys = ITKeyboardConstants.aAlternateKeys
eAlternateKeys = ITKeyboardConstants.eAlternateKeys
iAlternateKeys = ITKeyboardConstants.iAlternateKeys
oAlternateKeys = ITKeyboardConstants.oAlternateKeys
uAlternateKeys = ITKeyboardConstants.uAlternateKeys
sAlternateKeys = ITKeyboardConstants.sAlternateKeys
cAlternateKeys = ITKeyboardConstants.cAlternateKeys
nAlternateKeys = ITKeyboardConstants.nAlternateKeys
}
// MARK: Provide Layout
func setITKeyboardLayout() {
getITKeys()
currencySymbol = "€"
currencySymbolAlternates = euroAlternateKeys
spaceBar = "spazio"
language = "Italiano"
invalidCommandMsgWikidata = "Non in Wikidata"
invalidCommandTextWikidata1 =
"Wikidata è un grafo della conoscenza modificabile in modo collaborativo, gestito dalla Wikimedia Foundation. Serve come fonte di dati aperti per progetti come Wikipedia e innumerevoli altri."
invalidCommandTextWikidata2 =
"Scribe utilizza i dati linguistici di Wikidata per molte delle sue funzionalità principali. Otteniamo informazioni come il genere dei sostantivi, la coniugazione dei verbi e molto altro!"
invalidCommandTextWikidata3 =
"Puoi creare un account su wikidata.org per unirti alla comunità che supporta Scribe e tanti altri progetti. Aiutaci a diffondere informazioni libere in tutto il mondo!"
invalidCommandMsgWiktionary = "Non in Wiktionary"
invalidCommandTextWiktionary1 =
"Wiktionary è un dizionario modificato in modo collaborativo e gestito dalla Wikimedia Foundation. Serve come fonte di dati linguistici liberi per progetti come Wikipedia e innumerevoli altri."
invalidCommandTextWiktionary2 =
"Scribe utilizza i dati di Wiktionary per fornire traduzioni per il suo comando Traduci. I nostri dati derivano dalle numerose coppie linguistiche create dalla community di Wiktionary!"
invalidCommandTextWiktionary3 =
"Puoi creare un account su wiktionary.org per unirti alla community che supporta Scribe e tanti altri progetti. Aiutaci a diffondere informazioni libere in tutto il mondo!"
baseAutosuggestions = ["ho", "non", "ma"]
numericAutosuggestions = ["utenti", "anni", "e"]
translateKeyLbl = "Tradurre"
translatePlaceholder = "Inserisci una parola"
translatePrompt = commandPromptSpacing + "it -› \(getControllerLanguageAbbr()): "
translatePromptAndCursor = translatePrompt + commandCursor
translatePromptAndPlaceholder = translatePromptAndCursor + " " + translatePlaceholder
translatePromptAndColorPlaceholder = NSMutableAttributedString(
string: translatePromptAndPlaceholder
)
translatePromptAndColorPlaceholder.setColorForText(
textForAttribute: translatePlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
conjugateKeyLbl = "Coniugare"
conjugatePlaceholder = "Inserisci un verbo"
conjugatePrompt = commandPromptSpacing + "Coniugare: "
conjugatePromptAndCursor = conjugatePrompt + commandCursor
conjugatePromptAndPlaceholder = conjugatePromptAndCursor + " " + conjugatePlaceholder
conjugatePromptAndColorPlaceholder = NSMutableAttributedString(
string: conjugatePromptAndPlaceholder
)
conjugatePromptAndColorPlaceholder.setColorForText(
textForAttribute: conjugatePlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
pluralKeyLbl = "Plurale"
pluralPlaceholder = "Inserisci un nome"
pluralPrompt = commandPromptSpacing + "Plurale: "
pluralPromptAndCursor = pluralPrompt + commandCursor
pluralPromptAndPlaceholder = pluralPromptAndCursor + " " + pluralPlaceholder
pluralPromptAndColorPlaceholder = NSMutableAttributedString(string: pluralPromptAndPlaceholder)
pluralPromptAndColorPlaceholder.setColorForText(
textForAttribute: pluralPlaceholder,
withColor: UIColor(cgColor: commandBarPlaceholderColorCG)
)
alreadyPluralMsg = "Già plurale"
}