在OSX中以编程方式获取应用程序文件夹的名称 [英] Programmatically get the name of the Application Folder in OSX

查看:69
本文介绍了在OSX中以编程方式获取应用程序文件夹的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在美国和欧洲,应用程序文件夹命名为Applications,但是在中文或日语本地化下如何命名?

In the USA and Europe the application folder is named Applications, but under Chinese or Japanese localization how is it named?

是否可以通过编程方式获取文件夹的名称?

Is there a way to programmatically get the name of the folder?

推荐答案

文件系统中的目录名称始终为英文.这些目录可以附加本地化名称以显示给用户,但是这些不是您用来访问目录的名称.来自 国际化编程主题 :

The directory names in the filesystem are always in English. The directories can have localized names attached to them for displaying to the user, but those aren't the names you use to access the directories. From Internationalization Programming Topics:

您需要知道应用程序中的本地化路径名并适当显示它们.本地化的路径名仅用于显示目的,在访问文件系统时切勿使用.在处理代码中的文件和目录时,包括在需要写入缓存或用户首选项时,应继续使用实际的路径名.唯一应该使用本地化路径名的时间是,当您想通过应用程序的用户界面向用户显示该路径时.

You need to be aware of localized path names in your application and display them appropriately. Localized path names are for display purposes only and should never be used when accessing the file system. You should continue to use the actual pathname when working with files and directories in your code, including when you need to write to caches or user preferences. The only time you should use a localized path name is when you want to display that path to the user through your application’s user interface.

也就是说,您可以使用NSSearchPathForDirectoriesInDomains以编程方式获取路径:

That said, you get get the path programmatically using NSSearchPathForDirectoriesInDomains:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSLocalDomainMask, YES);
// Returns an NSArray containing the string "/Applications"

您也可以使用-[NSFileManager URLsForDirectory:inDomains:]:

NSArray *urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationDirectory inDomains:NSLocalDomainMask];
// Returns an NSArray containing the NSURL "file://localhost/Applications"

如果需要本地化名称显示给用户,请查看

If you need the localized names to display to the user, look at Internationalization Programming Topics.

这篇关于在OSX中以编程方式获取应用程序文件夹的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆