Is it possible to build localization into console apps, developed in SwiftUI in Xcode26. I have created a catalog, (.xcstrings file) with an English and fr-CA string. I have tried to display the French text without success. I am using the console app to test a package which also has English/French text. English text works fine in both package and the console main, but I cannot generate the French. From what I can discover so far it's not possible without bundling it as a .app, (console app). Looking for anyone who has crossed this bridge.
Localization in Swift macOS console Apps.
Just to clarify, "console" is Apple's UI for viewing data from the "unified logging system" and crash reports.
If you want to localize a command-line tool using Apple's localization framework, then you must bundle it in an app. But you can directly run the executable in Contents/MacOS and it will run in the current localization. You can even supply:
-AppleLanguages "(fr)"
on the command line to force a specific language.
All of this might only work if you are actually running a full user session and running the app in Terminal. If you are logging in remotely or something, all bets are off. That's a different environment and sometimes these things won't work.
Some Apple command-line tools get around this by linking to bundled frameworks that are, themselves, localized. I guess you could to that too.
by console, I am referring to a command line tool. My intention was to use the command line tool to test a package I am working on, as the eventual target will be a window app, I may abandon my efforts to localize my command line tool. I am using Swift Testing to unit test the package. I was hoping to hear from someone who had actually done this already.
by console, I am referring to a command line tool.
Yes. I realize that. But use of the word "console" is triggering. It's better to say "Terminal" or "command-line" to minimize the distress of your fellow developer.
My intention was to use the command line tool to test a package I am working on, as the eventual target will be a window app, I may abandon my efforts to localize my command line tool. I am using Swift Testing to unit test the package. I was hoping to hear from someone who had actually done this already.
I'm not sure what you're trying to do there. I do have an app that can operate both normally and on the command line. So I can verify that it does work. But unless you have very specific requirements, and someone paying your bills for you, stay far away from any kind of command line tool on the Mac.
The command line is a radically different environment and is wholly unsuitable for testing a normal app.
If you want to do unit testing, I guess that's fine. You can use the Xcode debugger too. Just be aware that modern versions of Xcode integrate that horrible "console" tool.
Depending on what kind of app you're developing, your development machine may not be an adequate platform for testing at all. You may need a virtual machine to isolate all the systemwide developer modifications. In some cases, you'll need a separate machine that has never run Xcode.
Good luck!
I have managed to wrap a "command line tool" into a .app package and to test my package localization. while this works it's obviously not the idle way to test a package localization. Just waiting to see if I get any more responses from someone who has actually tried to do this. Just to recap, there is nothing special here, just a command line tool with a Localization.xcstrings file that has one sentence both in English and fr-CA.