检测系统语言更改OS X.

时间:2016-12-20 15:48:33

标签: c++ objective-c macos

有没有办法在OS X下检测系统语言更改事件?

我试图在developer.apple.com上搜索,但没有结果。

我正在寻找C ++ / Obj-C的解决方案。

1 个答案:

答案 0 :(得分:1)

如果你在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];

只要方法采用languageChanged:对象,您就可以将NSNotification命名为- (void)languageChanged:(NSNotification *)notification { // New preferred language. NSString *language = [[NSLocale preferredLanguages] firstObject]; }

HTML:

<div id="email-templates" class="email-templates" ng-repeat="template in templateList | orderBy: 'display_name'">
    <div class="template-name" aria-label="Changed Name" uib-tooltip="Changed Name" "="" ng-click="loadTemplate(template)" role="button" tabindex="0">
        <span>Changed Name</span>
        <div class="list-icon-container">
            <i class="template-delete template-report-icon icon delete-icon" tabindex="0" aria-label="Delete an Email Template" uib-tooltip="Delete an Email Template" ng-click="deleteTemplate(template)" role="button"></i>
            <i class="template-report-icon icon angle-right-icon icon-xs" tabindex="0"></i>
        </div>
    </div>
</div> 


   EmailTemplates Property File :

this.templateList = element.all(by.repeater("template in templateList"));
this.templateName = this.templateList.all(by.css('[ng-click="loadTemplate(template)"]'));
this.deleteBtn = this.templateName.all(by.css('[ng-click="deleteTemplate(template)"]'));
this.confirmDelete = element(by.css('button[translate="ZillaMain.DeleteModalConfirmButton"]'));

Test File: 
var EmailTemplates = require('../../.././pages/EmailTemplates');

describe('AddEmailTemplate-', function() {
it(TestSuiteName + 'Verify that User is able to Delete a Template', function() {
  var TempName = 'Test';
  EmailTemplates.templateName.getAttribute("aria-label").then(function(labels) {
    EmailTemplates.templateList.count().then(function(total) {
        console.log("total no of Email temp=" +total);
        for (var i = 0; i < total; i++) {
            if (labels[i] === TempName) {                    
                console.log("Template Name found delete it :" +i);
                browser.actions().mouseMove(EmailTemplates.templateName.get(i)).perform().then(function(){
                                            browser.actions().mouseMove(EmailTemplates.deleteBtn.get(i)).click();
                        EmailTemplates.confirmDelete.click();
                        });

                } 
            }
       });
    });
  });
});

请查看NSDistributedNotificationCenter docs了解详情。

相关问题