Remove resources at runtime

In principle, I know that in OSX, an app’s resources such as bitmaps and language files are read-only by the app which contains them.

But is there any way to delete some using a shell command (run as sudo?)
What I want to do is delete language files (eg the folder de.lproj ) based upon user choice, so that when the app next runs, it appears in the user’s chosen language rather than whatever the OS is set to be.
I can do it using Finder if I supply an admin password, and it doesn’t break the code signature, so it must be possible by some route.
Im just not familiar enough with shell commands to know what to issue…

What if a different user (or the same user) on the computer wants to revert the language (and you removed the support files). I’ve never done this, but I think you want to be modifying the configuration files; similar to following posts:
https://forum.xojo.com/57954-forcing-a-locale/
https://blog.xojo.com/2013/12/17/how-os-x-chooses-a-language/
https://blog.xojo.com/2014/03/05/picking-a-language-at-runtime/

I apologize in advanced if you already looked at these, but removing the language files seemed a little extreme. But perhaps I completely misread the intent.

Jeff, don‘t do it.
This will break your app‘s code signature.

[quote]Jeff, don‘t do it.
This will break your app‘s code signature.[/quote]

You would expect so, but It doesn’t seem to do that, and I have talked people through this manually.

Nope. I have people whose locale should be French but want the app to run in English. Changing the whole system is not viable, even temporarily.

I know. And I have considered it. But after trying this approach on even one window, I decided I am not going to go through the whole app and create a system that programatically changes all the menu items based on a database.

Really, we could use a runtime app property that makes this happen.
After all, when a window is displayed /created, the app is getting the string resources after querying the OS locale.
All we need is something that says ‘ignore what you found, use this language instead’

Right now, I know that just deleting the fr.lproj folder achieves exactly what I need, making a French system run in English.

There is a system preferences where you can pick language per app.

Thats new… Catalina only… Thanks for that.
I think about 30% of my customers have mentioned Catalina so far

Easiest solution is this:
https://apps.apple.com/de/app/app-language-chooser/id451732904?affId=1864973&ign-mpt=uo%3D4&mt=12

You can also do it programmatically with declares, to achieve this: (works on iOS, untested on macOS)

UserDefaults.standard.set(["fr"], forKey: "AppleLanguages") (Change “fr” to the desired language code)

Does this declare set it per app or set the users chosen language to French ?

That code will change the language to French, only for the app that runs that code => per app.

However, the app must be closed then re-opened for the changes to be applied.

EDIT: that code works for iOS and I assume it works also for MacOS. I haven’t tested it as I do not make desktop apps anymore.

[quote=482622:@Jeff Tullin]how-os-x-chooses-a-language/
Nope. I have people whose locale should be French but want the app to run in English. Changing the whole system is not viable, even temporarily.[/quote]
Jeff, the info on the blog is similar to usage in stackoverflow. If you look at the syntax, “defaults write com.xojo.xojo AppleLanguages -array en”, it doesn’t change the OS language but rather the specific application language. But there are plenty of articles that to use it on Mojave and Catalina one must elevate the privilege of shell and terminal on the target computer. So that may not work for you in all cases.

And indeed it didn’t for me when I tried it on 10.14

Yes, I suspect that may be the best route for me to recommend.

But I still dont see why Xojo couldnt have a simple switch. It gets resources after asking for the locale.
It cant be hard to have a locale override, surely?

Acana App Language is doing the change, so it must be possible. The “defaults write” hasn’t worked for a long time.

Xojo isnt localized into any languages so that probably plays into why it does not work for Xojo itself

its not but requires some work on your part since there’s nothing built in

We use defaults write {BUNDLE_ID} AppleLanguages ‘(“es”)’ for instance and it works great.

{BUNDLE_ID} is taken from the Mac Build Settings

We use the originally proposed hack(Yuck) on PC.