Setting a preferred Language

I have most of my Apps localised in 5 languages which responds to the language in the system settings.

If the user wants the app to run in one of the other languages different to the system language how do I set for example System = English, App = French ?

How do you test your localisations? Changing the language of an app has been in macOS since Mojave:

1 Like

Hi Beatrix,
That bit works fine when the user changes the language in the system settings. If that part is set to German but they would like to use it in a classroom perhaps in a French class and don’t want to change the system settings is there a way to make my app only appear with the French menus and printouts and access the other labels in the Localised Strings?

In code?

I use this (Mac only)

sub ChangeLanguageTo(strLanguageCode as string)
dim thestring as string
dim s as new shell

if targetwin32 then 
  msgbox "Mac only"
  thestring = "defaults write **com.mysite.myapp**  AppleLanguages  '(""XX"")' "
  thestring = replace(thestring,"XX",strLanguageCode)
  s.Execute thestring
  Msgbox "The app needs to shut down to make this change"
end if
end sub
1 Like

Did you have a look at the lower part of my screenshot? You can change the language of each app. If you want mixed localisations then you are on your own.

Hi Beatrix,

Sorry yes that makes sense thanks. I was trying to do it in code maybe as a saved preference.

Thanks Jeff I’ll give that a try.

Hi Jeff,

This doesn’t look right

defaults write AppleLanguages ‘(“DE”)’ ??

Does this set the value that @Beatrix_Willius was highlighting in the Language Region Settings?

I think it would take a total redesign of your app with YOU taking care of the localization. Like reading Locale.Current at start up and saving it into user defined one as App.MyCurrentLocale

And all the time, using it to get the constant values for your user locale settings.

It will make #dynamicConstValues useless

You should handle those too.

Changing the localization would be changing App.MyCurrentLocale

I think you’re fighting against the built-in MacOS feature. As Beatrix showed, there is already a way to change an app’s language, which takes care of everything for you (even system menus, like inside the  menu are localised). That’s definitively the preferred way.

1 Like

Apple introduced the ability to set an app language via system settings with macOS 12 (or 11?).
Before, you had to use a terminal or execute a shell script to go via „defaults write“ to change the language of an app. There is a way to permanently change the language, another does change it only for the next time, you use the app.

I tried that as per Jeff’s suggestion above but nothing seemed to change

thestring = “defaults write com.mysite.myapp AppleLanguages '(”“XX”")’ "
thestring = replace(thestring,“XX”,strLanguageCode)

s.Execute thestring

I tried
the string = "defaults write AppleLanguages ‘(“DE”)’ "

Ok perhaps a redesign is necessary.

Different but related question:

What if we are keeping the App language the same as the system but just want the Print Routines to access the Localised Strings of a different language, is that possible?

I tested it again here, and it worked.
For this forum, the only thing I changed in the code was that uid

I’m on Monterey… what are you running?
Maybe something changed (again!)

Sonoma 14.1.1 (23B81)

Sure? Basic stuff as

Var word As String = kMyConstantWord("pt") // Get the Portuguese version of kMyConstantWord

word =  kMyConstantWord("en_AU")  // Australian English

word =  kMyConstantWord(language_code)  // whatever valid code

Yes it is.

Var s As String
s = kHello("fr")  // gets you   s = "Bonjour"
s = kHello("en")    // gets you     s = "Hello"
s = kHello("en_UK")     // gets you      s = "Welcome"
1 Like

en_UK is invalid, use en_GB instead.

Open a terminal window and type in:

defaults write -app CrosswordWizard AppleLanguages '("de")'

The -app switch allows yout to use the App-Name instead of the bundle id.

I tried

defaults write -app Crossword%20Wizard%20V6 AppleLanguages ‘(“de”)’

but it said couldn’t find App of that name