Forum > Cocoa
macOS FormatSettings & Phil Hess's NSFormat.pas
(1/1)
Zoë:
Free Pascal's RTL doesn't correctly initialize FormatSettings on macOS, even when using clocale. This has been brought up a few times previously, but the threads are all old.
If you set the System Settings > Language & Region to "German (Switzerland)", aka "Deutsch (Schweiz)" and the Region to "Switzerland", it uses right single quotes (’) as the number grouping separator. If you do that and then create a LCLCocoa project with the clocale unit included, using "Format('%0.n')" will either show commas or omit the separator entirely, depending on whether you launch it from Terminal or Finder.
On his webpage, Phil Hess (@phil) has a "Useful Objective Pascal source code" zip that contains an NSFormat.pas unit to correctly initialize the FormatSettings record based on the macOS system settings. You need to add NSFormat.pas to your uses clause and then include a call to "GetNSFormatSettings(FormatSettings)" somewhere in your startup code. It's already licensed under the modified LGPL.
This seems like behavior that should be included out of the box, either in the FPC RTL/packages or LCLCocoa. I'm emailing Phil about this too, but he hasn't posted here or updated his GitHub in quite a few years, so I don't know if I should expect a response.
We've had to make a few tweaks to his version over the years, and I just published our current copy with version history as a GitHub gist. We're only shipping on macOS, not iOS, so I don't know what considerations that might have.
The FPC RTL initializes the Windows FormatSettings in SysUtils, and the Linux/Unix ones in cLocale. The LCL Interfaces.pas units already include cwstring. It seems like the relevant ones should include clocale or the NSFormat functionality too.
I didn't want to jump straight to "Here's a patch" since it's mostly Phil's code and would involve potentially both the FPC RTL and LCL, but I could pull that together. Anyone have any thoughts?
AlexTP:
@Rich2014 makes good work for Cocoa, he may make a patch for Cocoa. But for RTL, I guess, your patch will be very welcome. In the bugtracker.
Navigation
[0] Message Index