I want to retrieve the localized name for a path on Mac OS X. I cobbled together the code below from various sources.
My Mac is currently set to the French locale, set French as the primary language, rebooted, I reset the LANG environment variable in the terminal to fr_FR.UTF-8, but I cannot seem to get the localized path for the folder (e.g. /Users/bll/Music). The locale seems to be working, the localized name does show up in the finder (Musique).
What am I missing here?
(I'm not a Mac programmer, not an objective-c programmer, don't speak french).
Edit: Updated with current code, Info.plist file
(I do understand the issues with display names with / characters embedded, just not going to worry about that at this time).
code:
#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>
Compilation:
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