简体   繁体   English

检测系统语言更改OS X

[英]Detect system language change OS X

Is there any way to detect the system language change event under OS X? 有什么方法可以检测OS X下的系统语言更改事件?

I've tried to search on the developer.apple.com, but with no results. 我试图在developer.apple.com上搜索,但没有结果。

I'm looking for a solution on C++/Obj-C. 我正在寻找C ++ / Obj-C上的解决方案。

If you're working in Objective-C/Swift, you can use NSDistributedNotificationCenter to watch for language change notifications: 如果您使用的是Objective-C / Swift,则可以使用NSDistributedNotificationCenter来监视语言更改通知:

// You are not required to register self -- this can be any object, and the selector name can be anything taking one argument.
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChanged:) name:@"AppleLanguagePreferencesChangedNotification" object:nil];

You can name languageChanged: whatever you'd like, as long as the method takes an NSNotification object: 您可以将languageChanged:命名为任意名称,只要该方法采用NSNotification对象即可:

- (void)languageChanged:(NSNotification *)notification {
    // New preferred language.
    NSString *language = [[NSLocale preferredLanguages] firstObject];
}

Take a look at the NSDistributedNotificationCenter docs for more info. 查看NSDistributedNotificationCenter文档以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM