Get System Language X-Platform?

Is there an X-platform (well Mac and Windows) of determining the system language?

I am workin with Truetype/Opentype font files. Getting the information I want from the font files about the fonts is relatively easy. (Though I am guess at the meanings of some things).

The files contain strings of the font family and style names in the various languages the font support (I think!). I think I can retrieve all the or , the strings for any specific language, but of course the ones I would usually want would the ones for the system language.

Is there anyway I can determine the system on language on Mac and Win? I know the language codes returned (if I can get them!) won’t be the same Xplatform, but I can deal with that.

It would seem to me the Xojo framework should have a way to to this but if so I am missing it… If not I could deal with declares.

Anybody know how to do this?

Thanks,

  • Karen

Hi, Karen!
You can get the current system locale language code by using the following:

var systemLang as String = Locale.Current.Identifier

– Anthony

2 Likes

It’s also worth noting that most people achieved this in the past by using localized constants.

1 Like

Thanks… It gives me a way forward is there is not a better one.

I had not thought to use locale because I avoided the Xojo framework well as API 2 so far (Don’t me started ranting about API 2 again!)

TruetypeFiles use platform specific numeric language codes that (I think) correlate with what you would get from declares not iso-639 strings… I suspect the truetype standard predates the iso standard.

I guess I can try and and construct dictionaries to go from iso-639 strings to the platform specific codes so I know which strings to look for.

I originally thought about using localized constants but that seemed rather cumbersome and was hoping to be able to get the OS specific codes not to have to worry about the details so much…

Thanks,
-Karen

1 Like

I can help with the macOS. You can read the value of “AppleLocale” from the NSUserDefaults (either with my App Kit, MBS, or declares).

On my system it returns “en_TW” as string.

1 Like

That should be the same thing you get from

Locale.Current.Identifier

Can you confirm?

If you do decide to create a table of some sort, this page from the MS docs might be helpful.

And this page appears to contain platform-specific listings of, at least some of, the numeric language codes.

Thanks, but I won’t need the declares… After seeing tehresult of teh declare, my best guess is that the Mac language codes that Truetype files use are from pre-OSX classic Mac OS as that is when the spec was originally created.

Looks l will need to create a dictionary or another mechanism to look up the codes truetype uses myself.

I suspect the windows numeric code could be gotten from some sort of declare as nothing ever goes away there!

-Karen

Thanks… Those are ISO 639-2 3 letter codes… Does locale return ISO 639-2 including 3 character codes or only ISO 639-1 2 character codes?

-Karen

Looks like I needed to read the truetype spec more… I did not fully grasp the language handling… The string Locale returns may be there…

I only looked at Format 0 and did not even look at Format 1 for the name table. I figured Format 0 would be always be there no matter how old the font, so it would be best just to use that…

However Format 1 which came later has the language strings… And if the table is Format 1 then the numeric language codes for individual strings CAN BE (but don’t have to be) indexes to the language strings and not the Format 0 codes

So I need to be able to handle both the old codes as well as the newer language string like those locale returns even if it is Format 1 if i want to handle all cases.

Thanks
-Karen