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

Use available keyboard layouts when selecting language-specific filters #1530

Open
ameshkov opened this issue Jan 26, 2025 · 0 comments
Open

Comments

@ameshkov
Copy link
Member

Issue Details

Currently, we rely on the OS language in order to select language-specific filter lists.

This may not be enough. For instance, the user may prefer to use English as the default language by OS, but they could actually be a speaker of a different language.

Proposed solution

In addition to that OS language we need to also rely on available keyboard layouts and extract language codes from it.

Code example to select available keyboard layouts:

import Foundation
import Carbon

func getAvailableKeyboardLayouts() -> [String] {
    var layouts: [String] = []
    
    // Create a search dictionary to filter for keyboard input sources
    let searchDict: [String: Any] = [
        kTISPropertyInputSourceType as String: kTISTypeKeyboardLayout as String
    ]
    
    // Get the list of input sources
    if let inputSources = TISCreateInputSourceList(searchDict as CFDictionary, false)?.takeRetainedValue() as? [TISInputSource] {
        for source in inputSources {
            if let layoutName = TISGetInputSourceProperty(source, kTISPropertyLocalizedName) {
                layouts.append(layoutName as! String)
            }
        }
    }
    return layouts
}

// Example usage
let keyboardLayouts = getAvailableKeyboardLayouts()
print("Available Keyboard Layouts:")
keyboardLayouts.forEach { print($0) }

Alternative solution

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants