mirror of
https://github.com/ONLYOFFICE/desktop-apps.git
synced 2026-04-07 14:09:22 +08:00
[macos] send system keyboard lang to editor
This commit is contained in:
@ -45,6 +45,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (void)init;
|
||||
+ (NSDictionary *)availableLanguages;
|
||||
+ (NSDictionary *)keyboardLanguages;
|
||||
+ (NSString *)appLanguageCode;
|
||||
+ (void)setAppLanguageCode:(NSString *)code;
|
||||
+ (BOOL)isUILayoutDirectionRtl;
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
|
||||
#import "ASCLinguist.h"
|
||||
#import "ASCConstants.h"
|
||||
#import <Carbon/Carbon.h>
|
||||
|
||||
@implementation ASCLinguist
|
||||
|
||||
@ -86,6 +87,44 @@ static BOOL uiLayoutDirectionRTL = NO;
|
||||
return uiLayoutDirectionRTL;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)keyboardLanguages {
|
||||
NSMutableDictionary * outdict = [NSMutableDictionary dictionary];
|
||||
CFArrayRef sourceList = TISCreateInputSourceList(NULL, false);
|
||||
if ( sourceList ) {
|
||||
CFIndex count = CFArrayGetCount(sourceList);
|
||||
for (CFIndex i = 0; i < count; i++) {
|
||||
TISInputSourceRef source = (TISInputSourceRef)CFArrayGetValueAtIndex(sourceList, i);
|
||||
|
||||
// Get only keyboard input sources
|
||||
CFTypeRef type = TISGetInputSourceProperty(source, kTISPropertyInputSourceType);
|
||||
if ( CFEqual(type, kTISTypeKeyboardLayout) || CFEqual(type, kTISTypeKeyboardInputMode) ) {
|
||||
CFStringRef localizedName = TISGetInputSourceProperty(source, kTISPropertyLocalizedName);
|
||||
NSString *name = (__bridge NSString *)localizedName;
|
||||
|
||||
// Get the language codes (ISO 639 format)
|
||||
CFArrayRef languages = TISGetInputSourceProperty(source, kTISPropertyInputSourceLanguages);
|
||||
if ( languages && CFArrayGetCount(languages) > 0 ) {
|
||||
// Get the first language code (usually the primary one)
|
||||
CFStringRef firstLang = CFArrayGetValueAtIndex(languages, 0);
|
||||
NSString *langString = (__bridge NSString *)firstLang;
|
||||
|
||||
outdict[langString] = name;
|
||||
// NSArray *components = [langString componentsSeparatedByString:@"-"];
|
||||
// NSString *languageCode = components[0];
|
||||
// if (components.count > 1) {
|
||||
// NSString *region = components[1];
|
||||
// NSLog(@"Language: %@ (ISO code: %@-%@)", name, languageCode, region);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(sourceList);
|
||||
}
|
||||
|
||||
return outdict;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)availableLanguages {
|
||||
return @{
|
||||
@"en-US": @{@"name": @"English (United States)", @"enname": @""},
|
||||
|
||||
@ -87,6 +87,10 @@
|
||||
}
|
||||
|
||||
[self setParameter:@"lang" withString:[ASCLinguist appLanguageCode]];
|
||||
|
||||
NSMutableDictionary * keybLangs = [NSMutableDictionary dictionary];
|
||||
[keybLangs setObject:[ASCLinguist keyboardLanguages] forKey:@"langs"];
|
||||
[_jsVariables setObject:keybLangs forKey:@"keyboard"];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
Reference in New Issue
Block a user