Adding localised strings to info.plist

My new app needs access to the Contacts. This works fine if I add the info.plist file from the MBS example. However, my app is localised and I want localised reason strings. At some point this must have worked for my old app. But when I use the code below access to Contacts is denied. How do I get localised strings into the info.plist?


dim dbg as String
if debugBuild then dbg = ".debug"
dim appNameForShell as string = PropertyValue("App.MacOSXAppName") + dbg +".app" + "/Contents/Info.plist"
appNameForShell = replaceall(appNameForShell, " ", "\ ")
Dim AppPath As String = CurrentBuildLocation + "/" + ReplaceAll(CurrentBuildAppName, " ", "\ ")
if right(AppPath, 4) <> ".app" then appPath = appPath + ".app"

'contacts
dim command as String = "/bin/echo 'NSContactsUsageDescription = ""Nur Deine Email-Adresse und Dein Name werden benötigt.""; '>>" + appPath + "/Contents/Resources/de.lproj/InfoPlist.strings"
Call DoShellCommand(command)

Instead of putting localized strings directly in Info.plist, reference them using key/value strings, and provide localized versions in InfoPlist.strings files.

Use this syntax in your Info.plist for localizable values:

<key>CFBundleDisplayName</key>
<string>$(CFBundleDisplayName)</string>

Create these in the appropriate .lproj folders (e.g. en.lproj, fr.lproj, etc.).

Example: en.lproj/InfoPlist.strings:
CFBundleDisplayName = "My App";

Example: fr.lproj/InfoPlist.strings:
CFBundleDisplayName = "Mon App";

2 Likes

That’s what I’m already doing. The path for the file is de.lproj/InfoPlist.strings.

Edit: This is what should happen. But as far as I can see the main entry in the plist is missing:

Sigh… so why do the AppleScripts work with this plist but not the Contacts? I hate this stupid sugar. I’ll check that out tomorrow.

Those localized folders belong at the top level of your bundle, not in the Resources directory.

But you also need an entry in the top-level Info.plist file that references the name in the file.

If it is intended for the AppleStore, in order for the app to be approved yuo may need this item too:

< key>NSContactsUsageDescription<< /key>
< string>Users may request data from Contacts app. Contacts will not be shared or uploaded.< /string>

edited: added < plus space in order to may key appear. Needless to say that the space will have to deleted

Carlo, did you read her initial post? She wants to localize that string, she already knows she needs it.

Sorry for the unecessary noise.

1 Like

Got this finally solved. Greg was correct, I was missing the correct entry in the main plist file. Also the Xojo script was missing double quotes around each '““NSContactsUsageDescription”” . The translations do not go to the top level of the bundle but the Resources directory.

It’s fine to read Carlo’s post as well, as reference for other users who need this information as well.

1 Like