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

Hebrew Keyboard update to HEInterfaceKeyboard.swift #495

Merged
merged 10 commits into from
Aug 31, 2024
Merged
237 changes: 153 additions & 84 deletions Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
/**
DanielGevaZA marked this conversation as resolved.
Show resolved Hide resolved
* Constants and functions to load the Hebrew Scribe keyboard.
*
* Copyright (C) 2024 Scribe
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// HEInterfaceVariablesTemp.swift
// Scribe

import UIKit

public enum HebrewKeyboardConstants {
static let defaultCurrencyKey = "$"
static let currencyKeys = ["$", "€", "£", "¥"]
static let defaultCurrencyKey = ""
static let currencyKeys = ["", "€", "£", "$"]

// Alternate key vars.
static let keysWithAlternates = [""]
static let keysWithAlternatesLeft = [""]
static let keysWithAlternatesRight = [""]

Check failure on line 10 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
}

struct HebrewKeyboardProvider: KeyboardProviderProtocol {
// iPhone keyboard layouts.
static func genPhoneLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["פ", "ם", "ן", "ו", "ט", "א", "ר", "ק", "delete"])
.addRow(["פ", "ם", "ן", "ו", "ט", "א", "ר", "ק", ""])
DanielGevaZA marked this conversation as resolved.
Show resolved Hide resolved
.addRow(["ף", "ך", "ל", "ח", "י", "ע", "כ", "ג", "ד", "ש"])
.addRow(["ץ", "ת", "צ", "מ", "נ", "ה", "ב", "ס", "ז"])
.addRow(["123", "selectKeyboard", "space", "return"]) // "undo", "accent"
.addRow(["123", "selectKeyboard", "רווח", "הכנס"])
.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"]) // "undo", "accent"
.addRow(["#+=", ".", ",", "?", "!", "'", ""])
.addRow(["אבג", "selectKeyboard", "רווח", "הכנס"])
.replaceKey(row: 1, column: 6, to: currencyKey)
.build()
}
Expand All @@ -54,8 +35,8 @@
let keyboardBuilder = KeyboardBuilder()
.addRow(["[", "]", "{", "}", "#", "%", "^", "*", "+", "="])
.addRow(["_", "\\", "|", "~", "<", ">", "€", "£", "¥", "·"])
.addRow(["123", ".", ",", "?", "!", "'", "delete"])
.addRow(["ABC", "selectKeyboard", "space", "return"]) // "undo", "accent"
.addRow(["123", ".", ",", "?", "!", "'", ""])
.addRow(["אבג", "selectKeyboard", "רווח", "הכנס"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at it, we have space and return in the Russian keyboard, so I think these should be reverted. Not ABC, that's correct, but the actual Hebrew for these keys will be substituted in later, or for return it similarly will be an icon like for X :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do


if currencyKeys.count < 3 {
return keyboardBuilder.build()
Expand All @@ -67,70 +48,158 @@
.build()
}
}

Check failure on line 51 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// iPad keyboard layouts.
static func genPadLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "+"])
.addRow([",", ".", "פ", "ם", "ן", "ו", "ט", "א", "ר", "ק", "delete"])
.addRow(["ף", "ך", "ל", "ח", "י", "ע", "כ", "ג", "ד", "ש"])
.addRow(["ץ", "ת", "צ", "מ", "נ", "ה", "ב", "ס", "ז", "return"])
.addRow(["selectKeyboard", ".?123", "space", ".?123", "hideKeyboard"]) // "undo"
.build()
}
static func genPadLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "+"])
.addRow([",", ".", "פ", "ם", "ן", "ו", "ט", "א", "ר", "ק", ""])
.addRow(["ף", "ך", "ל", "ח", "י", "ע", "כ", "ג", "ד", "ש"])
.addRow(["ץ", "ת", "צ", "מ", "נ", "ה", "ב", "ס", "ז", "הכנס"])
.addRow(["selectKeyboard", ".?123", "רווח", ".?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"]) // "undo"
// .replaceKey(row: 1, column: 4, to: currencyKey)
.build()
}
static func genPadNumberKeys(currencyKey: String) -> [[String]] {
return KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", ""])
.addRow(["!", "@", "#", "&", "_", "-", "'", "\"", "(", ")", "הכנס"])
.addRow(["#+=", "%", "...", "&", ";", ":", "=", "+", "/", "?", "#+="])
.addRow(["selectKeyboard", "אבג", "רווח", "אבג", "hideKeyboard"])
// .replaceKey(row: 1, column: 4, 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"]) // "undo"
static func genPadSymbolKeys(currencyKeys: [String]) -> [[String]] {
let keyboardBuilder = KeyboardBuilder()
.addRow(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "*", ""])
.addRow(["^", "€", "$", "£", "[", "]", "'", "\"", "<", ">", "הכנס"])
.addRow(["123", "§", "|", "~", "*", "·", "{", "}", "\\", "~", "123"])
.addRow(["selectKeyboard", "אבג", "רווח", "אבג", "hideKeyboard"])

if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return keyboardBuilder
.replaceKey(row: 1, column: 1, to: currencyKeys[0])
.replaceKey(row: 1, column: 2, to: currencyKeys[1])
.replaceKey(row: 1, column: 3, to: currencyKeys[2])
if currencyKeys.count < 3 {
return keyboardBuilder.build()
} else {
return keyboardBuilder
.replaceKey(row: 1, column: 1, to: currencyKeys[0])
.replaceKey(row: 1, column: 2, to: currencyKeys[1])
.replaceKey(row: 1, column: 3, to: currencyKeys[2])
.build()
}
}

Check failure on line 90 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
// Expanded iPad keyboard layouts for wider devices.
static func genPadExpandedLetterKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["§", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "❌"])
.addRow([SpecialKeys.indent, "/", "'", "פ", "ם", "ן", "ו", "ט", "א", "ר", "ק", "[", "]", "+"])
.addRow([SpecialKeys.capsLock, "ף", "ך", "ל", "ח", "י", "ע", "כ", "ג", "ד", "ש", ",", "\"", "הכנס"])
.addRow(["⇧", ";", "ץ", "ת", "צ", "מ", "נ", "ה", "ב", "ס", "ז", ".", "⇧"])
.addRow(["selectKeyboard", ".?123", "רווח", ".?123", "hideKeyboard"])
.build()
}
}

// Expanded iPad keyboard layouts for wider devices.
static func genPadExpandedLetterKeys() -> [[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", ".?123", "space", ".?123", "hideKeyboard"]) // "microphone", "scribble"
.build()
static func genPadExpandedSymbolKeys() -> [[String]] {
return KeyboardBuilder()
.addRow(["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "<", ">", "❌"])
.addRow([SpecialKeys.indent, "[", "]", "{", "}", "#", "%", "^", "*", "+", "=", "\"", "|", ""])
.addRow([SpecialKeys.capsLock, "°", "/", ":", ";", "(", ")", "$", "&", "@", "£", "¥", "", "הכנס"])
.addRow(["⇧", "", "?", "!", "~", "", "'", "\"", "_", ",", ".", "-", ""])
.addRow(["selectKeyboard", "אבג", "רווח", "אבג", "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"]) // "undo"
.addRow(["shift", "…", "?", "!", "~", "≠", "'", "\"", "_", ",", ".", "-", "shift"]) // "redo"
.addRow(["selectKeyboard", "ABC", "space", "ABC", "hideKeyboard"]) // "microphone", "scribble"
.build()
/// Gets the keys for the Hebrew keyboard.


func getHEKeys() {
guard let userDefaults = UserDefaults(suiteName: "group.be.scri.userDefaultsContainer") else {
fatalError()
}

Check failure on line 120 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
var currencyKey = HebrewKeyboardConstants.defaultCurrencyKey
var currencyKeys = HebrewKeyboardConstants.currencyKeys
let dictionaryKey = controllerLanguage + "defaultCurrencySymbol"

Check failure on line 124 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
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)
}

Check failure on line 133 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
if DeviceType.isPhone {
letterKeys = HebrewKeyboardProvider.genPhoneLetterKeys()
numberKeys = HebrewKeyboardProvider.genPhoneNumberKeys(currencyKey: currencyKey)
symbolKeys = HebrewKeyboardProvider.genPhoneSymbolKeys(currencyKeys: currencyKeys)
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())

Check failure on line 139 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
leftKeyChars = ["ק", "1", "-", "[", "_"]
rightKeyChars = ["פ", "0", "\"", "=", "·"]
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
} else {
// Use the expanded keys layout if the iPad is wide enough and has no home button.
if usingExpandedKeyboard {
letterKeys = HebrewKeyboardProvider.genPadExpandedLetterKeys()
symbolKeys = HebrewKeyboardProvider.genPadExpandedSymbolKeys()

Check failure on line 148 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
allKeys = Array(letterKeys.joined()) + Array(symbolKeys.joined())
} else {
letterKeys = HebrewKeyboardProvider.genPadLetterKeys()
numberKeys = HebrewKeyboardProvider.genPadNumberKeys(currencyKey: currencyKey)
symbolKeys = HebrewKeyboardProvider.genPadSymbolKeys(currencyKeys: currencyKeys)

Check failure on line 154 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
letterKeys.removeFirst(1)

Check failure on line 156 in Keyboards/LanguageKeyboards/Hebrew/HEInterfaceVariables.swift

View workflow job for this annotation

GitHub Actions / Run SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
allKeys = Array(letterKeys.joined()) + Array(numberKeys.joined()) + Array(symbolKeys.joined())
}

leftKeyChars = ["1", "ק"]
rightKeyChars = ["הכנס", "hideKeyboard"]
centralKeyChars = allKeys.filter { !leftKeyChars.contains($0) && !rightKeyChars.contains($0) }
}
}

/// Gets the keys for the Hebrew keyboard.
func getHEKeys() {}

/// Provides the Hebrew keyboard layout.
func setHEKeyboardLayout() {}
func setHEKeyboardLayout() {
getHEKeys()

currencySymbol = ""
currencySymbolAlternates = roubleAlternateKeys
spaceBar = "רווח"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this is where the spacebars text is replaced :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or set up to be replaced 😇

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in the rest of the code should it still be the english "Space"? or is replacing it with hebrew like I did fine? Same apply for the enter/return button?

language = "עברית"
invalidCommandMsg = "אין מידע"
baseAutosuggestions = ["אתמ", "אני", "היי"]
numericAutosuggestions = ["", "", ""]

translateKeyLbl = "Translate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also similarly need these to be localized into Hebrew :) Same for Conjugate and Plural.

translatePlaceholder = "Translate"
translatePrompt = commandPromptSpacing + "he -› \(getControllerLanguageAbbr()): "
translatePromptAndCursor = translatePrompt + commandCursor
translatePromptAndPlaceholder = translatePromptAndCursor + " " + translatePlaceholder
translatePromptAndColorPlaceholder = NSMutableAttributedString(string: translatePromptAndPlaceholder)
translatePromptAndColorPlaceholder.setColorForText(textForAttribute: translatePlaceholder, withColor: UIColor(cgColor: commandBarPlaceholderColorCG))

conjugateKeyLbl = "Conjugate"
conjugatePlaceholder = "Conjugate"
conjugatePrompt = commandPromptSpacing + "Conjucation: "
conjugatePromptAndCursor = conjugatePrompt + commandCursor
conjugatePromptAndPlaceholder = conjugatePromptAndCursor + " " + conjugatePlaceholder
conjugatePromptAndColorPlaceholder = NSMutableAttributedString(string: conjugatePromptAndPlaceholder)
conjugatePromptAndColorPlaceholder.setColorForText(textForAttribute: conjugatePlaceholder, withColor: UIColor(cgColor: commandBarPlaceholderColorCG))

pluralKeyLbl = "Plural"
pluralPlaceholder = "Plural"
pluralPrompt = commandPromptSpacing + "Plural: "
pluralPromptAndCursor = pluralPrompt + commandCursor
pluralPromptAndPlaceholder = pluralPromptAndCursor + " " + pluralPlaceholder
pluralPromptAndColorPlaceholder = NSMutableAttributedString(string: pluralPromptAndPlaceholder)
pluralPromptAndColorPlaceholder.setColorForText(textForAttribute: pluralPlaceholder, withColor: UIColor(cgColor: commandBarPlaceholderColorCG))
alreadyPluralMsg = "Already in plural form"
}


// Created by Daniel Geva on 2024/08/30.
Loading
Loading