Skip to content

Commit

Permalink
Merge pull request #12 from thisIsTheFoxe/feature/general-latin-layout
Browse files Browse the repository at this point in the history
Add general latin language layout
  • Loading branch information
thisIsTheFoxe authored Oct 8, 2023
2 parents b6f408c + efbd386 commit e710554
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
28 changes: 25 additions & 3 deletions Sources/SimpleKeyboard/Models/Language.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public enum Language: CaseIterable {

case english, german, spanish, french, russian, hindi
case swedish, danish, norwegian, finnish

/// General purpose layout using QWERTY with the common diacritics
case latinWithAccents

var alternateKeys: [String: String] {
switch self {
Expand All @@ -35,6 +38,17 @@ public enum Language: CaseIterable {
// Though not in the official alphabet, á is a Swedish (old-fashioned) letter. In native Swedish personal names, ü and è and others are also used.
case .swedish: return ["a":"á", "u":"ü", "e": "è"]
case .finnish: return ["s": "š", "z": "ž"]
case .latinWithAccents:

// 300 = Grave; 301 = Acute;
// 302 = Circumflex; 303 = Tilde;
// 308 = Diaeresis; 30A = Ring;
// 327 = Cedilla; 30C = Caron;
return [
"\u{0300}": "\u{0301}",
"\u{0302}": "\u{0303}",
"\u{0308}": "\u{030A}",
"\u{0327}": "\u{030C}",]
default: return [:]
}
}
Expand Down Expand Up @@ -90,25 +104,33 @@ public enum Language: CaseIterable {
["a", "s", "d", "f", "g", "h", "j", "k", "l", "æ", "ø"],
["z", "x", "c", "v", "b", "n", "m"]
]

case .norwegian:
result = [
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "ö", "ä"],
["z", "x", "c", "v", "b", "n", "m"]
]

case .finnish:
result = [
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "å"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "ø", "æ"],
["z", "x", "c", "v", "b", "n", "m"]
]

case .latinWithAccents:
result = [
["q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "\u{0300}"],
["a", "s", "d", "f", "g", "h", "j", "k", "l", "\u{0302}", "\u{0308}"],
["z", "x", "c", "v", "b", "n", "m", "\u{0327}"]
]
}

if areUppercased {
result = result.map { $0.map { $0.uppercased() } }
result = result.map { $0.map {
let upper = $0.uppercased()
if $0 != upper { return upper }
return alternateKeys[$0] ?? $0
} }
}

return result
Expand Down
1 change: 1 addition & 0 deletions Sources/SimpleKeyboard/Views/KeyButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct KeyButton: View, ClickableKey {
}

/// Replaces the last typed character with another (special) character. E.g. "a" -> "ä"
@available(*, deprecated, message: "Use `Language.alternateKeys` instead")
struct AccentKeyButton: View, ClickableKey {
@Binding var text: String
/// The lookup for modified characters all lowercased. E.g. `["a": "ä"]`
Expand Down
2 changes: 1 addition & 1 deletion Sources/SimpleKeyboard/Views/SimpleStandardKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct SimpleStandardKeyboard_Previews: PreviewProvider {
isUpperCase: true))
SimpleStandardKeyboard(
settings: KeyboardSettings(
language: .spanish,
language: .latinWithAccents,
textInput: nil,
theme: .system,
actionButton: .search,
Expand Down

0 comments on commit e710554

Please sign in to comment.