【发布时间】:2017-09-19 20:25:33
【问题描述】:
我想检索 Mac OS X 上路径的本地化名称。 我从各种来源拼凑出以下代码。
我的 Mac 当前设置为法语区域设置,将法语设置为主要语言,重新启动,我将终端中的 LANG 环境变量重置为 fr_FR.UTF-8,但我似乎无法获取文件夹的本地化路径(例如 /Users/bll/Music)。语言环境似乎有效,本地化名称确实有效 出现在取景器中(音乐)。
我在这里错过了什么?
(我不是 Mac 程序员,也不是 Objective-c 程序员,不会说法语)。
编辑:使用当前代码更新,Info.plist 文件
(我确实了解嵌入 / 字符的显示名称的问题,只是目前不担心)。
代码:
#import "Foundation/NSObject.h"
#import "Foundation/NSFileManager.h"
#import "Foundation/NSProcessInfo.h"
#include <stdio.h>
#include <stdlib.h>
#include <MacTypes.h>
int
main (int argc, const char * argv[])
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *path = @"";;
NSString *npath = @"";
NSArray *npathcomp;
NSUInteger count;
if (argc > 1) {
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
path = arguments[1];
npath = path;
if (*argv[1] == '/') {
npathcomp = [fm componentsToDisplayForPath:path];
count = npathcomp.count - 1;
npath = [[npathcomp subarrayWithRange:NSMakeRange (1,count)]
componentsJoinedByString:@"/"];
}
}
printf ("/%s\n", [npath UTF8String]);
return 0;
}
Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleAllowMixedLocalizations</key>
<true/>
<key>CFBundleDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleDisplayName</key>
<string>localizeddirname</string>
<key>CFBundleExecutable</key>
<string>localizeddirname</string>
<key>CFBundleGetInfoString</key>
<string>Copyright 2017 Brad Lanam, Walnut Creek CA USA</string>
<key>CFBundleIdentifier</key>
<string>org.bdj.localizeddirname</string>
<key>CFBundleName</key>
<string>localizedirname</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleVersion</key>
<string>1.0.0</string>
<key>LSMinimumSystemVersion</key>
<string>10.6.0</string>
</dict>
</plist>
编译:
cp -p localizeddirname.plist Info.plist
clang \
-v \
-mmacosx-version-min=10.9 \
-framework Cocoa \
-o localizeddirname \
-Wl,-sectcreate,__TEXT,__info_plist,Info.plist \
localizeddirname.m
rm -f Info.plist
【问题讨论】:
-
如果有帮助,无论用户设置什么语言,您都可以随时访问
"/Users/bll/Music"的音乐文件夹(翻译后的名称仅为方便用户显示,但目录路径不变) .看到这个post -
'displayNameAtPath' 返回应用支持的语言的本地化名称。比较 Xcode 和 TextEdit 的打开对话框。
-
"...对于您的应用支持的语言":如何更改程序以表明它支持所有语言?
标签: objective-c macos