Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System to pick a translation language for each keyboard #476

Merged
merged 51 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
20b5433
Refactor to simplify code
Jag-Marcel Jun 4, 2024
825712e
Merge branch 'main' into translation-picker
Jag-Marcel Jun 17, 2024
1fc7bee
Merge branch 'main' into translation-picker
Jag-Marcel Jun 18, 2024
fa14ae0
Added right-hand label to InfoChildTableCell (#469)
Jag-Marcel Jun 24, 2024
5f3eb9e
Added new TableView under keyboard settings
Jag-Marcel Jun 26, 2024
5c3edda
Merge branch 'main' into translation-picker
Jag-Marcel Jul 17, 2024
151b107
Available tag that isn't needed anymore
Jag-Marcel Jul 17, 2024
da74dbf
Added cell type for radio buttons
Jag-Marcel Jul 20, 2024
819b090
Added selection view for radio selections
Jag-Marcel Jul 20, 2024
f8ca58e
Small fix to stop OK from being added to localization file
Jag-Marcel Jul 20, 2024
a3c1491
Changed keys for new strings
Jag-Marcel Jul 20, 2024
ea3aa80
Added functionality to tl language selection view
Jag-Marcel Jul 23, 2024
30e6c80
Added sending the user back to previous view on selection in Selectio…
Jag-Marcel Jul 23, 2024
f03bd00
Language specificity for translation language
Jag-Marcel Jul 25, 2024
55ffc83
Set up system for language specific translations
Jag-Marcel Jul 26, 2024
299e535
SwiftLint fixes
Jag-Marcel Jul 26, 2024
8799094
Squashed 'Scribe/i18n/' changes from 13a4d74..cd28e5e
Jag-Marcel Jul 26, 2024
84d0c61
Merge commit '87990943226346615e039e22e9f9f568e9dedae4' into translat…
Jag-Marcel Jul 26, 2024
d1d654f
Squashed 'Scribe/i18n/' changes from cd28e5e..d9b2226
Jag-Marcel Jul 26, 2024
888b249
Merge commit 'd1d654f12a644108be065b81615b374dcf8654b9' into translat…
Jag-Marcel Jul 26, 2024
8204f16
Merge branch 'main' into translation-picker
Jag-Marcel Jul 26, 2024
4b03f5b
Merge branch 'main' into translation-picker
andrewtavis Jul 30, 2024
ac52b0d
Reflect changed translation language in keyboard command
Jag-Marcel Aug 8, 2024
39a345e
Merge branch 'main' into translation-picker
Jag-Marcel Aug 9, 2024
4958ff2
merge fix
Jag-Marcel Aug 9, 2024
18fa6cf
New translation data tables + EN app group for conflict
andrewtavis Aug 18, 2024
210531d
Merge branch 'main' into translation-picker
Jag-Marcel Aug 19, 2024
6f02245
Revert changes from 20b5433
Jag-Marcel Aug 19, 2024
dcbd0f3
Add back changes from 20b5433
Jag-Marcel Aug 19, 2024
0e81679
Edited to account for new translation setup and made smaller fixes
Jag-Marcel Aug 19, 2024
fd507ff
SwiftLint fixes
Jag-Marcel Aug 19, 2024
167ca8b
Reactivated English translation
Jag-Marcel Aug 20, 2024
296c0e7
Restyling for translation language keyboards
Jag-Marcel Aug 20, 2024
ede2450
Added text to English conjugation and plural command bars
Jag-Marcel Aug 20, 2024
a97b74c
Changed behaviour for querying translations
Jag-Marcel Aug 21, 2024
64ade23
Merge branch 'main' into translation-picker
andrewtavis Aug 24, 2024
d4e2b0a
Update data with new Translation structure
andrewtavis Sep 15, 2024
998f68f
Enabled translation queueing for all languages
Jag-Marcel Nov 8, 2024
a2f91f4
Spacing fixes
Jag-Marcel Nov 8, 2024
96739cf
Merge branch 'main' into translation-picker
Jag-Marcel Nov 8, 2024
88919d3
Removed unnecessary spaces
Jag-Marcel Nov 8, 2024
ee9ad7e
Fixed project.pbxproj file
Jag-Marcel Nov 8, 2024
82aa0db
Refactored directory structure to bundle views and cells together
Jag-Marcel Nov 8, 2024
5028b34
Squashed 'Scribe/i18n/' changes from 5bd9672..8c13530
andrewtavis Nov 9, 2024
f81d174
Partial Scribe-i18n update
andrewtavis Nov 9, 2024
684a15e
Squashed 'Scribe/i18n/' changes from 8c13530..718ab45
andrewtavis Nov 9, 2024
82dc38e
Update of xcstrings and Android values files
andrewtavis Nov 9, 2024
83e44c6
Updated code to use new keys and simplified logic to be more dynamic
Jag-Marcel Nov 9, 2024
a851736
i18n update?
Jag-Marcel Nov 10, 2024
5483007
Update translation data post particle removal and cap fixes
andrewtavis Nov 10, 2024
be3c69b
Update translation functionality to accept lower/uppercase + check upper
andrewtavis Nov 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pr_maintainer_checklist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- [ ] The CI unit test workflows within the [PR checks](https://github.com/scribe-org/Scribe-iOS/pull/${{ github.event.pull_request.number }}/checks) do not indicate new errors in the files changed

- [ ] The [CHANGELOG](https://github.com/scribe-org/Scribe-iOS/blob/main/CHANGELOG.md) has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

- name: First PR Contributor Email Check
id: first_interaction
uses: actions/first-interaction@v1
Expand Down
42 changes: 32 additions & 10 deletions Keyboards/KeyboardsBase/InterfaceVariables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func checkLandscapeMode() {

// Keyboard language variables.
var controllerLanguage = String()
var controllerLanguageAbbr = String()

// Dictionary for accessing language abbreviations.
let languagesAbbrDict = [
Expand All @@ -174,16 +173,23 @@ let languagesAbbrDict = [
]

let languagesStringDict = [
"English": NSLocalizedString("_global.english", value: "English", comment: ""),
"French": NSLocalizedString("_global.french", value: "French", comment: ""),
"German": NSLocalizedString("_global.german", value: "German", comment: ""),
"Italian": NSLocalizedString("_global.italian", value: "Italian", comment: ""),
"Portuguese": NSLocalizedString("_global.portuguese", value: "Portuguese", comment: ""),
"Russian": NSLocalizedString("_global.russian", value: "Russian", comment: ""),
"Spanish": NSLocalizedString("_global.spanish", value: "Spanish", comment: ""),
"Swedish": NSLocalizedString("_global.swedish", value: "Swedish", comment: "")
"English": NSLocalizedString("app._global.english", value: "English", comment: ""),
"French": NSLocalizedString("app._global.french", value: "French", comment: ""),
"German": NSLocalizedString("app._global.german", value: "German", comment: ""),
"Italian": NSLocalizedString("app._global.italian", value: "Italian", comment: ""),
"Portuguese": NSLocalizedString("app._global.portuguese", value: "Portuguese", comment: ""),
"Russian": NSLocalizedString("app._global.russian", value: "Russian", comment: ""),
"Spanish": NSLocalizedString("app._global.spanish", value: "Spanish", comment: ""),
"Swedish": NSLocalizedString("app._global.swedish", value: "Swedish", comment: "")
]

func getKeyInDict(givenValue: String, dict: [String: String]) -> String {
for (key, value) in dict where value == givenValue {
return key
}
return ""
}

/// Returns the abbreviation of the language for use in commands.
func getControllerLanguageAbbr() -> String {
guard let abbreviation = languagesAbbrDict[controllerLanguage] else {
Expand All @@ -192,6 +198,17 @@ func getControllerLanguageAbbr() -> String {
return abbreviation
}

func getControllerTranslateLangCode() -> String {
let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer")!
let key = getControllerLanguageAbbr() + "TranslateLanguage"
if let translateLang = userDefaults.string(forKey: key) {
return translateLang
} else {
userDefaults.set("en", forKey: key)
return "en"
}
}

// Dictionary for accessing keyboard abbreviations and layouts.
let keyboardLayoutDict: [String: () -> Void] = [
// Layouts for French checked within setFRKeyboardLayout.
Expand All @@ -214,7 +231,12 @@ func setKeyboard() {
/// Sets the keyboard layouts given the chosen keyboard and device type.
func setKeyboardLayout() {
if commandState == .translate {
setENKeyboardLayout()
let translateLanguage = getKeyInDict(givenValue: getControllerTranslateLangCode(), dict: languagesAbbrDict)
if let setLayoutFxn = keyboardLayoutDict[translateLanguage] {
setLayoutFxn()
} else {
setENKeyboardLayout()
}
} else if let setLayoutFxn = keyboardLayoutDict[controllerLanguage] {
setLayoutFxn()
}
Expand Down
63 changes: 34 additions & 29 deletions Keyboards/KeyboardsBase/KeyboardKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,26 @@ class KeyboardKey: UIButton {

/// Adjusts the width of a key if it's one of the special characters on the iPhone keyboard.
func adjustPhoneKeyWidth() {
if key == "ABC" || key == "АБВ" {
if ["ABC", "АБВ"].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 2).isActive = true
} else if key == "delete"
|| key == "#+="
|| key == "shift"
|| key == "selectKeyboard" {
// Cancel Russian keyboard key resizing if translating as the keyboard is English.
if controllerLanguage == "Russian"
&& keyboardState == .letters
&& commandState != .translate {
} else if ["delete", "#+=", "shift", "selectKeyboard"].contains(key) {
if keyboardState == .letters
&& (
(
commandState != .translate
&& controllerLanguage == "Russian"
) || (
commandState == .translate
&& getControllerTranslateLangCode() == "ru"
)) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
}
} else if key == "123"
|| key == ".?123"
|| key == "return"
|| key == "hideKeyboard" {
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if row == 2 {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
Expand All @@ -256,7 +255,7 @@ class KeyboardKey: UIButton {
scalarShiftKeyWidth = 1.5
scalarSpecialKeysWidth = 1.0

if key == "ABC" || key == "АБВ" {
if ["ABC", "АБВ"].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["#+=", "selectKeyboard"].contains(key) {
Expand All @@ -281,15 +280,18 @@ class KeyboardKey: UIButton {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarReturnKeyWidth).isActive = true
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if key == "return"
if DeviceType.isPad
&& key == "return"
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate
(
commandState != .translate
&& ["English", "Portuguese", "Italian"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)
)
&& row == 1
&& DeviceType.isPad {
&& row == 1 {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * scalarReturnKeyWidth).isActive = true
} else {
Expand All @@ -300,22 +302,25 @@ class KeyboardKey: UIButton {
widthAnchor.constraint(equalToConstant: keyWidth).isActive = true
}
} else {
if key == "ABC" || key == "АБВ" {
if ["ABC", "АБВ"].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["delete", "#+=", "shift", "selectKeyboard", SpecialKeys.indent, SpecialKeys.capsLock].contains(key) {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1).isActive = true
} else if ["123", ".?123", "return", "hideKeyboard"].contains(key) {
if key == "return"
if DeviceType.isPad
&& key == "return"
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate
(
commandState != .translate
&& ["English", "Portuguese", "Italian"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)
)
&& row == 1
&& DeviceType.isPad {
&& row == 1 {
layer.setValue(true, forKey: "isSpecial")
widthAnchor.constraint(equalToConstant: numSymKeyWidth * 1.5).isActive = true
} else {
Expand Down
108 changes: 67 additions & 41 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ class KeyboardViewController: UIInputViewController {
} else {
conjugationToDisplay = "was/were " + conjugationToDisplay
}
} else if index == 3 && allConjugations[index] == "presPerfTPS" {
} else if index == 2 && allConjugations[index] == "presPerfTPS" {
conjugationToDisplay = "have/" + conjugationToDisplay
} else if index == 3 && allConjugations[index] == "presPerfTPSCont" {
conjugationToDisplay = "have/" + conjugationToDisplay
Expand Down Expand Up @@ -1707,60 +1707,77 @@ class KeyboardViewController: UIInputViewController {
var leftPadding = CGFloat(0)
if DeviceType.isPhone
&& key == "y"
&& ["German", "Swedish"].contains(controllerLanguage)
&& commandState != .translate
&& disableAccentCharacters != true {
&& (
(
commandState != .translate
&& ["German", "Swedish"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["de", "sv"].contains(getControllerTranslateLangCode())
)
)
&& !disableAccentCharacters {
leftPadding = keyWidth / 3
addPadding(to: stackView2, width: leftPadding, key: "y")
}
if DeviceType.isPhone
&& key == "a"
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate
|| (
(
controllerLanguage == "German"
|| controllerLanguage == "Spanish"
|| controllerLanguage == "Swedish"
(
commandState != .translate
&& (
["English", "Portuguese", "Italian"].contains(controllerLanguage)
|| (
["German", "Spanish", "Swedish"].contains(controllerLanguage)
&& disableAccentCharacters
)
)
&& disableAccentCharacters == true
)) {
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)) {
leftPadding = keyWidth / 4
addPadding(to: stackView1, width: leftPadding, key: "a")
}
if DeviceType.isPad
&& key == "a"
&& !usingExpandedKeyboard
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate
) {
(
commandState != .translate
&& ["English", "Portuguese", "Italian"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)) {
leftPadding = keyWidth / 3
addPadding(to: stackView1, width: leftPadding, key: "a")
}
if DeviceType.isPad
&& key == "@"
&& !usingExpandedKeyboard
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate) {
(
commandState != .translate
&& ["English", "Portuguese", "Italian"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)) {
leftPadding = keyWidth / 3
addPadding(to: stackView1, width: leftPadding, key: "@")
}
if DeviceType.isPad
&& key == "€"
&& !usingExpandedKeyboard
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| commandState == .translate) {
(
commandState != .translate
&& ["English", "Portuguese"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["en", "pt"].contains(getControllerTranslateLangCode())
)) {
leftPadding = keyWidth / 3
addPadding(to: stackView1, width: leftPadding, key: "€")
}
Expand Down Expand Up @@ -1847,27 +1864,35 @@ class KeyboardViewController: UIInputViewController {
var rightPadding = CGFloat(0)
if DeviceType.isPhone
&& key == "m"
&& ["German", "Swedish"].contains(controllerLanguage)
&& commandState != .translate
&& disableAccentCharacters != true {
&& (
(
commandState != .translate
&& ["German", "Swedish"].contains(controllerLanguage)
) || (
commandState == .translate
&& ["de", "sv"].contains(getControllerTranslateLangCode())
)
)
&& !disableAccentCharacters {
rightPadding = keyWidth / 3
addPadding(to: stackView2, width: rightPadding, key: "m")
}
if DeviceType.isPhone
&& key == "l"
&& (
controllerLanguage == "English"
|| controllerLanguage == "Portuguese"
|| controllerLanguage == "Italian"
|| commandState == .translate
|| (
(
controllerLanguage == "German"
|| controllerLanguage == "Spanish"
|| controllerLanguage == "Swedish"
(
commandState != .translate
&& (
["English", "Portuguese", "Italian"].contains(controllerLanguage)
|| (
["German", "Spanish", "Swedish"].contains(controllerLanguage)
&& disableAccentCharacters
)
)
&& disableAccentCharacters == true
)) {
) || (
commandState == .translate
&& ["en", "pt", "it"].contains(getControllerTranslateLangCode())
)) {
rightPadding = keyWidth / 4
addPadding(to: stackView1, width: rightPadding, key: "l")
}
Expand Down Expand Up @@ -2348,6 +2373,7 @@ class KeyboardViewController: UIInputViewController {

case "Translate":
if let selectedText = proxy.selectedText {
commandState = .translate
queryWordToTranslate(queriedWordToTranslate: selectedText)

if commandState == .invalid { // invalid state
Expand Down
Loading
Loading