0

OS X + Excel 2016

我们不会说英语的人希望我们的计算机本地化,但我们想使用 Excel 英语公式。为此,我们需要让 Excel 使用另一种语言,从而为应用设置 AppleLanguages GlobalPreference 以覆盖系统设置。

=SUM() 比 =SOMME() 或 =NPV() 比 =VAN() 更容易学习和讨论

主意

为了让我的用户更容易,我正在编写一个 Python+Cocoa 应用程序,它基本上会询问用户他/她想要的语言并将其存储在首选项文件中。

在 CLI 中,要将(仅)Excel 设置为英文,请运行:

 $ defaults write com.microsoft.Excel AppleLanguages "('en’)”

 我的问题

我跑:

newLanguageCode = ['zh-CN']
CoreFoundation.CFPreferencesSetAppValue('AppleLanguages', newLanguageCode, 'com.microsoft.Excel')

问题是它写入 ~/Library/Preferences/com.microsoft.Excel.plist 而不是 ~/Library/Containers/com.microsoft.Excel/Data/Library/Preferences/com.microsoft.Excel.plist

如何告诉 CFPreferencesSetAppValue 写入 Container 而不是 home ?

附录

minidefrancois:Library francois$ defaults read ~/Library/Preferences/com.microsoft.Excel.plist 
{
    AppleLanguages =     (
        "zh-CN"
    );
}


minidefrancois:Library francois$ defaults read -app /Applications/Microsoft\ Excel.app/
{
    AppExitGraceful = 0;
    AppleLanguages =     (
        en
    );
    ExceptionEnum = 0;
    NSRecentDocumentsLimit = 0;
    "NSWindow Frame FileUIWindowFrameAutoSaveName" = "276 322 1046 626 0 0 1680 1027 ";
    OCModelLanguage = "fr-FR";
    OCModelVersion = "0.838";
    OUIWhatsNewLastShownLink = 624954;
    SendAllTelemetryEnabled = 1;
    SessionBuildNumber = 151008;
    SessionId = "55FDAD65-D013-4184-A5A5-CBF747DC563D";
    SessionStartTime = "10/21/2015 10:49:43.997";
    SessionVersion = "15.15";
    TemplateDownload = 1;
    kFileUIDefaultTabID = 1;
    kOUIRibbonDefaultCollapse = 0;
    kSubUIAppCompletedFirstRunSetup1507 = 1;
}


minidefrancois:Library francois$ defaults read ~/Library/Containers/com.microsoft.Excel/Data/Library/Preferences/com.microsoft.Excel.plist
{
    AppExitGraceful = 0;
    AppleLanguages =     (
        en
    );
    ExceptionEnum = 0;
    NSRecentDocumentsLimit = 0;
    "NSWindow Frame FileUIWindowFrameAutoSaveName" = "276 322 1046 626 0 0 1680 1027 ";
    OCModelLanguage = "fr-FR";
    OCModelVersion = "0.838";
    OUIWhatsNewLastShownLink = 624954;
    SendAllTelemetryEnabled = 1;
    SessionBuildNumber = 151008;
    SessionId = "55FDAD65-D013-4184-A5A5-CBF747DC563D";
    SessionStartTime = "10/21/2015 10:49:43.997";
    SessionVersion = "15.15";
    TemplateDownload = 1;
    kFileUIDefaultTabID = 1;
    kOUIRibbonDefaultCollapse = 0;
    kSubUIAppCompletedFirstRunSetup1507 = 1;
}
minidefrancois:Library francois$ 
4

1 回答 1

0

感谢 Thomas Burgin 和 Greg Neagle:

需要将应用 ID 设置为:

NSHomeDirectory() + "/Library/Containers/com.microsoft.Excel/Data/Library/Preferences/com.microsoft.Excel"

我把它推到了https://github.com/ftiff/Office8n

以下是相关代码:

homeDirectory = NSHomeDirectory()
appName = homeDirectory + "/Library/Containers/com.microsoft.Excel/Data/Library/Preferences/com.microsoft.Excel”
propertyName = ‘AppleLanguages’ (unused here, will later)
_dropDown = objc.IBOutlet()

   def getPreference(self, appName, propertyName, _dropDown):
       result = CoreFoundation.CFPreferencesCopyAppValue('AppleLanguages', appName)
       # if it's an array, return only first value
       if isinstance(result, NSArray):
           result = result[0]
       language = self.codeToLanguage.get(result, "English")
       _dropDown.selectItemWithTitle_(language)
       return result

_label = @objc.IBAction

   def savePreference(self, propertyName, _value, appName, _label):
       propertyValue = []
       propertyValue.append(_value)
       CoreFoundation.CFPreferencesSetAppValue(propertyName, propertyValue, appName)
       CoreFoundation.CFPreferencesAppSynchronize(appName)
       NSLog("{appName}: {propertyName} = {propertyValue}".format(
                                                                  appName=appName,
                                                                  propertyName=propertyName,
                                                                  propertyValue=propertyValue
                                                                  ))
       _label.setStringValue_("Set to: " + self.codeToLanguage.get(propertyValue[0], "None"))
于 2015-10-21T16:22:22.317 回答