Skip to content

Commit

Permalink
Added conjugation functionality to EN keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Jag-Marcel committed Aug 13, 2024
1 parent 3c58551 commit d01b754
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 20 deletions.
93 changes: 83 additions & 10 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,15 @@ class KeyboardViewController: UIInputViewController {
.genitiveDefinite, .genitiveIndefinite, .genitiveDemonstrative
].contains(deCaseDeclensionState) {
formsDisplayDimensions = .view2x2
} else if controllerLanguage == "English" {
switch enConjugationState {
case .present, .presCont, .past, .future, .conditional:
formsDisplayDimensions = .view2x2
case .presSimp, .presPerf, .presPerfCont:
formsDisplayDimensions = .view1x2
case .pastCont:
formsDisplayDimensions = .view3x1
}
} else if commandState == .displayInformation {
formsDisplayDimensions = .view1x1
} else {
Expand Down Expand Up @@ -1423,7 +1432,7 @@ class KeyboardViewController: UIInputViewController {
conjugationStateFxn = conjugationFxn
}

if !["Russian", "Swedish"].contains(controllerLanguage) {
if !["English", "Russian", "Swedish"].contains(controllerLanguage) {
formFPS = conjugationStateFxn() + "FPS"
formSPS = conjugationStateFxn() + "SPS"
formTPS = conjugationStateFxn() + "TPS"
Expand Down Expand Up @@ -1451,6 +1460,24 @@ class KeyboardViewController: UIInputViewController {
formTopRight = swedishTenses[1]
formBottomLeft = swedishTenses[2]
formBottomRight = swedishTenses[3]
} else if controllerLanguage == "English" {
if formsDisplayDimensions == .view2x2 {
let englishTenses = enGetConjugationState()

formTopLeft = englishTenses[0]
formTopRight = englishTenses[1]
formBottomLeft = englishTenses[2]
formBottomRight = englishTenses[3]
} else if formsDisplayDimensions == .view1x2 {
let englishTenses = enGetConjugationState()

formLeft = englishTenses[0]
formRight = englishTenses[1]
} else if formsDisplayDimensions == .view3x1 {
formTop = "presPart"
formMiddle = "pastSimpCont"
formBottom = "pastSimpPluralCont"
}
}
}

Expand Down Expand Up @@ -1481,25 +1508,40 @@ class KeyboardViewController: UIInputViewController {
}

// Assign labels that have been set by SetConjugationLabels function.
// Other labels not assigned as they're not used in conjugation at this time.
formLblFPS.setTitle(" " + (formLabelsDict["FPS"] ?? ""), for: .normal)
formLblSPS.setTitle(" " + (formLabelsDict["SPS"] ?? ""), for: .normal)
formLblTPS.setTitle(" " + (formLabelsDict["TPS"] ?? ""), for: .normal)
formLblFPP.setTitle(" " + (formLabelsDict["FPP"] ?? ""), for: .normal)
formLblSPP.setTitle(" " + (formLabelsDict["SPP"] ?? ""), for: .normal)
formLblTPP.setTitle(" " + (formLabelsDict["TPP"] ?? ""), for: .normal)

formLblTop.setTitle(" " + (formLabelsDict["Top"] ?? ""), for: .normal)
formLblMiddle.setTitle(" " + (formLabelsDict["Middle"] ?? ""), for: .normal)
formLblBottom.setTitle(" " + (formLabelsDict["Bottom"] ?? ""), for: .normal)

formLblTL.setTitle(" " + (formLabelsDict["TL"] ?? ""), for: .normal)
formLblTR.setTitle(" " + (formLabelsDict["TR"] ?? ""), for: .normal)
formLblBL.setTitle(" " + (formLabelsDict["BL"] ?? ""), for: .normal)
formLblBR.setTitle(" " + (formLabelsDict["BR"] ?? ""), for: .normal)

if formsDisplayDimensions == .view3x2 {
formLblLeft.setTitle(" " + (formLabelsDict["Left"] ?? ""), for: .normal)
formLblRight.setTitle(" " + (formLabelsDict["Right"] ?? ""), for: .normal)

switch formsDisplayDimensions {
case .view3x2:
allConjugations = [formFPS, formSPS, formTPS, formFPP, formSPP, formTPP]
allConjugationBtns = get3x2FormDisplayButtons()
} else {
case .view3x1:
allConjugations = [formTop, formMiddle, formBottom]
allConjugationBtns = get3x1FormDisplayButtons()
case .view2x2:
allConjugations = [formTopLeft, formTopRight, formBottomLeft, formBottomRight]
allConjugationBtns = get2x2FormDisplayButtons()
case .view1x2:
allConjugations = [formLeft, formRight]
allConjugationBtns = get1x2FormDisplayButtons()
case .view1x1:
break
}

// Populate conjugation view buttons.
Expand All @@ -1511,8 +1553,12 @@ class KeyboardViewController: UIInputViewController {
styleBtn(btn: allConjugationBtns[index], title: invalidCommandMsg, radius: keyCornerRadius)
} else {
conjugationToDisplay = conjugationsToDisplay[index]
if inputWordIsCapitalized && deConjugationState != .indicativePerfect {
conjugationToDisplay = conjugationToDisplay.capitalized
if inputWordIsCapitalized {
if controllerLanguage == "English", conjugationToDisplay.count(of: " ") > 0 {
conjugationToDisplay = conjugationToDisplay.capitalize()
} else if deConjugationState != .indicativePerfect {
conjugationToDisplay = conjugationToDisplay.capitalized
}
}
styleBtn(btn: allConjugationBtns[index], title: conjugationToDisplay, radius: keyCornerRadius)
}
Expand Down Expand Up @@ -2411,19 +2457,46 @@ class KeyboardViewController: UIInputViewController {
loadKeys()

case "formTopLeft":
returnConjugation(keyPressed: sender, requestedForm: formTopLeft)
if controllerLanguage == "English" && enConjugationState == .present {
enConjugationState = .presSimp
conjViewShiftButtonsState = .bothInactive
} else {
returnConjugation(keyPressed: sender, requestedForm: formTopLeft)
}
loadKeys()

case "formTopRight":
returnConjugation(keyPressed: sender, requestedForm: formTopRight)
if controllerLanguage == "English" {
if enConjugationState == .present {
enConjugationState = .presCont
conjViewShiftButtonsState = .bothInactive
} else if enConjugationState == .past {
enConjugationState = .pastCont
conjViewShiftButtonsState = .bothInactive
} else {
returnConjugation(keyPressed: sender, requestedForm: formTopRight)
}
} else {
returnConjugation(keyPressed: sender, requestedForm: formTopRight)
}
loadKeys()

case "formBottomLeft":
returnConjugation(keyPressed: sender, requestedForm: formBottomLeft)
if controllerLanguage == "English" && enConjugationState == .present {
enConjugationState = .presPerf
conjViewShiftButtonsState = .bothInactive
} else {
returnConjugation(keyPressed: sender, requestedForm: formBottomLeft)
}
loadKeys()

case "formBottomRight":
returnConjugation(keyPressed: sender, requestedForm: formBottomRight)
if controllerLanguage == "English" && enConjugationState == .present {
enConjugationState = .presPerfCont
conjViewShiftButtonsState = .bothInactive
} else {
returnConjugation(keyPressed: sender, requestedForm: formBottomRight)
}
loadKeys()

case "formLeft":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ var formLabelsDict = [
"SPP": "",
"TPP": "",
"Top": "",
"Bottom": "",
"Middle": "",
"Bottom": "",
"TL": "",
"TR": "",
"BL": "",
Expand Down
35 changes: 34 additions & 1 deletion Keyboards/KeyboardsBase/ScribeFunctionality/Conjugate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,45 @@ func returnConjugation(keyPressed: UIButton, requestedForm: String) {
} else {
proxy.insertText(wordToReturn + getOptionalSpace())
}
} else if formsDisplayDimensions == .view3x1 {
wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0]
potentialWordsToReturn = wordToReturn.components(separatedBy: getOptionalSpace())

if inputWordIsCapitalized {
if controllerLanguage == "English", potentialWordsToReturn.count > 1 {
// Don't return a space as well as we have a perfect verb and the cursor will be between.
proxy.insertText(wordToReturn.capitalize())
} else {
proxy.insertText(wordToReturn.capitalized + getOptionalSpace())
}
} else {
proxy.insertText(wordToReturn + getOptionalSpace())
}
} else if formsDisplayDimensions == .view2x2 {
wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0]
potentialWordsToReturn = wordToReturn.components(separatedBy: " ")

if inputWordIsCapitalized {
proxy.insertText(wordToReturn.capitalized + getOptionalSpace())
if controllerLanguage == "English", potentialWordsToReturn.count > 1 {
// Don't return a space as well as we have a perfect verb and the cursor will be between.
proxy.insertText(wordToReturn.capitalize())
} else {
proxy.insertText(wordToReturn.capitalized + getOptionalSpace())
}
} else {
proxy.insertText(wordToReturn + getOptionalSpace())
}
} else if formsDisplayDimensions == .view1x2 {
wordToReturn = LanguageDBManager.shared.queryVerb(of: verbToConjugate, with: outputCols)[0]
potentialWordsToReturn = wordToReturn.components(separatedBy: " ")

if inputWordIsCapitalized {
if controllerLanguage == "English", potentialWordsToReturn.count > 1 {
// Don't return a space as well as we have a perfect verb and the cursor will be between.
proxy.insertText(wordToReturn.capitalize())
} else {
proxy.insertText(wordToReturn.capitalized + getOptionalSpace())
}
} else {
proxy.insertText(wordToReturn + getOptionalSpace())
}
Expand Down
109 changes: 105 additions & 4 deletions Keyboards/LanguageKeyboards/English/ENCommandVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,124 @@ func enSetConjugationLabels() {
for k in formLabelsDict.keys {
formLabelsDict[k] = ""
}

switch enConjugationState {
case .present, .past, .future, .conditional:
formLabelsDict["TL"] = "Simple"
formLabelsDict["TR"] = "Continuous"
formLabelsDict["BL"] = "Perfect"
formLabelsDict["BR"] = "Perfect Continuous"
case .presSimp, .presPerf, .presPerfCont:
formLabelsDict["Left"] = "I/you/plural"
formLabelsDict["Right"] = "he/she/it"
case .presCont:
formLabelsDict["TL"] = "Participle"
formLabelsDict["TR"] = "I"
formLabelsDict["BL"] = "you/plural"
formLabelsDict["BR"] = "he/she/it"
case .pastCont:
formLabelsDict["Top"] = "Participle"
formLabelsDict["Middle"] = "I/he/she/it"
formLabelsDict["Bottom"] = "you/plural"
}
}

/// What the conjugation state is for the conjugate feature.
enum ENConjugationState {
case present
case presSimp
case presCont
case presPerf
case presPerfCont
case past
case pastCont
case future
case conditional
}

var enConjugationState: ENConjugationState = .present

/// Sets the title of the command bar when the keyboard is in conjugate mode.
func enGetConjugationTitle() {}
func enGetConjugationTitle() -> String {
if inputWordIsCapitalized {
verbToDisplay = verbToConjugate.capitalized
} else {
verbToDisplay = verbToConjugate
}
switch enConjugationState {
case .present:
return commandPromptSpacing + "Present: " + verbToDisplay
case .presSimp:
return commandPromptSpacing + "Pr. Simple: " + verbToDisplay
case .presCont:
return commandPromptSpacing + "Pr. Continuous: " + verbToDisplay
case .presPerf:
return commandPromptSpacing + "Pr. Perfect: " + verbToDisplay
case .presPerfCont:
return commandPromptSpacing + "Pr. Perf. Continuous: " + verbToDisplay
case .past:
return commandPromptSpacing + "Past: " + verbToDisplay
case .pastCont:
return commandPromptSpacing + "Past Continuous: " + verbToDisplay
case .future:
return commandPromptSpacing + "Future: " + verbToDisplay
case .conditional:
return commandPromptSpacing + "Conditional: " + verbToDisplay
}
}

/// Returns the appropriate key in the verbs dictionary to access conjugations.
func enGetConjugationState() {}
func enGetConjugationState() -> [String] {
switch enConjugationState {
case .present:
return ["presSimp", "presFPSCont", "presPerfSimp", "presPerfSimpCont"]
case .presSimp:
return ["presSimp", "presTPS"]
case .presCont:
return ["presPart", "presFPSCont", "prePluralCont", "presTPSCont"]
case .presPerf:
return ["presPerfSimp", "presPerfTPS"]
case .presPerfCont:
return ["presPerfSimpCont", "presPerfTPSCont"]
case .past:
return ["pastSimp", "pastSimpCont", "pastPerf", "pastPerfCont"]
case .pastCont:
return ["presPart", "pastSimpCont", "pastSimpPluralCont"]
case .future:
return ["futSimp", "futCont", "futPerf", "futPerfCont"]
case .conditional:
return ["condSimp", "condCont", "condPerf", "condPerfCont"]
}
}

/// Action associated with the left view switch button of the conjugation state.
func enConjugationStateLeft() {}
func enConjugationStateLeft() {
switch enConjugationState {
case .present, .presSimp, .presCont, .presPerf, .presPerfCont, .pastCont:
break
case .past:
conjViewShiftButtonsState = .leftInactive
enConjugationState = .present
case .future:
enConjugationState = .past
case .conditional:
conjViewShiftButtonsState = .bothActive
enConjugationState = .future
}
}

/// Action associated with the right view switch button of the conjugation state.
func enConjugationStateRight() {}
func enConjugationStateRight() {
switch enConjugationState {
case .presSimp, .presCont, .presPerf, .presPerfCont, .pastCont, .conditional:
break
case .present:
conjViewShiftButtonsState = .bothActive
enConjugationState = .past
case .past:
enConjugationState = .future
case .future:
conjViewShiftButtonsState = .rightInactive
enConjugationState = .conditional
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ func setENKeyboardLayout() {
numericAutosuggestions = ["is", "to", "and"]
verbsAfterPronounsArray = ["have", "be", "can"]
pronounAutosuggestionTenses = [
"I": "presFPS",
"you": "presSPS",
"I": "presSimp",
"you": "presSimp",
"he": "presTPS",
"she": "presTPS",
"it": "presTPS",
"we": "presFPP",
"they": "presTPP"
"we": "presSimp",
"they": "presSimp"
]

translateKeyLbl = "Translate"
Expand Down

0 comments on commit d01b754

Please sign in to comment.