Settings bundle with string catalog

Is it possible to use a string catalog to localize a settings bundle?

Currently, to localize a Settings.bundle, we need to create a folder for each language with a single strings file inside.

For example:

Settings.bundle
    en.lproj > Root.strings
    fr.lproj > Root.strings
    de.lproj > Root.strings
    ...

Any way to convert that to a string catalog?

Thank you

Hi, This is a tricky one. As for Xcode 15.1 I did not find any way to do it semi-automatically like for Info.plist file. The sync seems not possible for Settings.bundle or Root.strings. But you can use string catalog for Settings.bundle manually. You just need to do some additional work.

What I did is as follows:

In my Resources folder (where I also have the whole Settings.bundle) I've added Root.xcstrings file manually (all languages, keys and strings). Because it will not be populated automatically as InfoPlist.xcstrings I had to manually copy all keys and strings from the original Root.plist. Please remember to NOT add Root.xcstrings to any target because it will trigger automatic stringfile compilation and you will find Root.strings inside your *.lproj folders in your final build. You don't want Root.strings in the top-level *.lproj but inside Settings.bundle.

Next, I've added a custom build phase to manually trigger xcstrings compilation with xcstringstool compile command like this:

#!/bin/bash

SETTINGS_BUNDLE="$CODESIGNING_FOLDER_PATH/Settings.bundle"
SETTINGS_XCSTRINGS="$SRCROOT/My App/Resources/Root.xcstrings"
xcstringstool compile "$SETTINGS_XCSTRINGS" --output-directory "$SETTINGS_BUNDLE"

This phase has to be added after Copy Bundle Resources.

As you can see, the generated Root.strings file lands in the build folder ($CODESIGNING_FOLDER_PATH) not in the source code. You don't need to commit them to your repo.

Next, I'll try to make an automatic sync Root.plist with my Root.xcstrings. I don't know how to extract all localizable texts from the Root.plist yet. I'll work on this. This way we could have the same functionality as for any swift files or storyboard/xib files.

It's a shame Apple did not give us automatic use of string catalog for Settings.bundle but at least it's possible to use it.

I've updated my old gist for script generating Root.strings from the Root.plist file. You can check it here: genstringsforsettingsbundle.swift.

After using that script I'm adding Root.strings to the project (I've used an empty project instead of my main project to not mess up anything). After that, you can right-click on the Root.strings file in the Xcode and use the "Migrate to String Catalog..." option. You will end up with proper Root.xcstrings file which will work as your base for translations.

Settings bundle with string catalog
 
 
Q