FileManager displayName(atPath:) no effect?

I logged in to macOS with my localization language.
try to perform following code. but always get "Documents".
What do I miss?

Apple Swift version 5.2.4
macOS 10.15.6
Xcode 11.6

code

let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
if paths.count > 0 {
    let doc = FileManager().displayName(atPath: paths[0])
    print(doc)
}

result

Documents

but always get "Documents".

How are you testing this? In an app? Or a command-line tool? Or something else?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@apple.com"

@eskimo I can reproduce this issue in my swift common-line tool. The main.swift is pasted below. macOS 13.4.1, Xcode Version 14.3.1.

import AppKit

let paths = NSSearchPathForDirectoriesInDomains(.downloadsDirectory, .userDomainMask, true)
if paths.count > 0 {
    let doc = FileManager().displayName(atPath: paths[0])
    print(doc)
}

The console outputs

Downloads
Program ended with exit code: 0

But the expected result for displayName(atPath:) should return "下载" for my system‘s localization language (Simplified Chinese)

Apple platforms go out of their way to avoid mixed localisation, that is, having one part of your app in language A while another part in in language B. I suspect what’s going on here is that Foundation thinks your command-line tool is localised for English and thus is giving you the English localisation.

This makes sense to me. In many ways you can think of a command-line tool as a plug-in for Terminal. Imagine your command-line tool prints the Documents folder name. You want that output to be aligned with the value that the user sees when they do an ls.

If you put this code into an app and localise the app for your target language, you should get the right value.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

FileManager displayName(atPath:) no effect?
 
 
Q