Localization problem in NSOpenPanel

My app is cross-platform and I don't use Xcode project.

All localization inside app is performed with an internal code and works fine.

There is a problem with localization in NSOpenPanel and NSSavePanel. They always appear on English and don't use macOS current language (French) of an user.

I added the following code to Info.plist :

Code Block
<key>CFBundleLocalizations</key>
<array>
   <string>en</string>
   <string>fr</string>
</array>


But NSOpenPanel still appears on English.

I checked macOS TextEdit app which shows NSOpenPanel correctly with current OS language. Its Info.plist doesn't set any CFBundleLocalizations records. How this app tells macOS what language should be used for NSOpenPanel?
Answered by wnsoft in 655303022
Thanks for your all replies.

I found a solution:
  1. Localization doesn't work if I use a symbolic link to an executable file.

The cross-platform compiler (Freepascal) created an executable outside APP bundle, and a symbolic link inside /MacOS folder.
It seems to be a bug in macOS, because I run APP bundle and localization must work. So I copied manually real executable to /MacOS folder (as for a release version) and now everything works fine.

2. Also I discovered that I can use one of two options:

A. Add CFBundleLocalizations records for each supported language.

B. Or add an empty folder for each language in /Contents/Resources - fr.lproj , de.lproj , etc.

Any of these variants for to use OS language in NSOpenPanel and NSSavePanel.

I hope that this info will be useful for for somebody else.

Are your strings present in .strings files in .lproj directories? Generally, fr.lproj will need to be present in your application bundle resources for macOS to pick-up that your app supports French.
All internal localization in my cross-platform app are stored in other files.

I tried to add an empty fr.lproj folder in /Resources - no result.

I checked VLC app with a correct NSOpenPanel. It contais fr.lproj in /Resources/ > InfoPlist.strings:

Code Block
CFBundleName = "VLC";
CFBundleDisplayName = "VLC";
CFBundleShortVersionString = "3.0.11.1";
CFBundleGetInfoString = "Copyright © 1996-2020 the VideoLAN team";
NSHumanReadableCopyright = "Copyright (c) 1996-2020 VLC authors and VideoLAN";


I added the same InfoPlist.strings file to my fr.lproj - the same result - everything in NSOpenPanel on English
Could you show you call for NSOpenPanel and define its attributes ?
Accepted Answer
Thanks for your all replies.

I found a solution:
  1. Localization doesn't work if I use a symbolic link to an executable file.

The cross-platform compiler (Freepascal) created an executable outside APP bundle, and a symbolic link inside /MacOS folder.
It seems to be a bug in macOS, because I run APP bundle and localization must work. So I copied manually real executable to /MacOS folder (as for a release version) and now everything works fine.

2. Also I discovered that I can use one of two options:

A. Add CFBundleLocalizations records for each supported language.

B. Or add an empty folder for each language in /Contents/Resources - fr.lproj , de.lproj , etc.

Any of these variants for to use OS language in NSOpenPanel and NSSavePanel.

I hope that this info will be useful for for somebody else.

Localization problem in NSOpenPanel
 
 
Q