After much searching and help from the Apple Developer forum, I found the answer to the problem below. It appears that I need to change the Development Language from "en" to "nl". This I could do by editing the file "project.pbxproj" inside my app's .xcodeproject file, by changing the line
Possibly there is a setting in Xcode that governs this, but I have not found it. Neither have I found a way to make this an Xcode standard, so that I will have to do it for all apps separately. But it works.
(Sorry for this lengthy post, but I try to be as complete as possible).
In this day of the project, dates are to be displayed, nicely formatted. For this, the following lines are added.
and to ContentView.swift:
It is then claimed that:
For me, I did not see the dates as I expected, i.e., they did not follow my local conventions. I looked into it and got more questions than answers.
In Apple's Developer Documentation I read for
I understand this as implying that the display of Date objects will follow local conventions, as indicated by the current Locale.
However, I have difficulty in getting this to work correctly.
To analyze the issue, I started with a fresh project, with the following ContentView.swift:
I ran it with the Simulator. This gave me a display with the following three lines:
So far, so good. I live in the Netherlands and my Mac is on locale "nl_NL" but apparently Xcode doesn't follow this. Fine.
But formatted() is supposed to follow locale, so I try the following: in the Settings app on the simulated device I set "iPhone language" to "Dutch" and "region" to "Nederland".
Upon restart of the simulation, I see the following:
So, changing language and region has had some effect. The region is now set to NL, and the dates display somewhat differently. But the language is still English: "May" in Dutch should be written "mei". Also, dates are formatted differently in Dutch.
I read somewhere that there are settings in the Scheme for the project that influence behaviour. So I went into Scheme/Run, Options tab, and changed App Language to Dutch and App Region to Netherlands. This gives:
So, no effect.
I finally followed a recipe I found on the Internet and added the following lines to ContentView.swift, just after the import SwiftUI line:
Running now gives:
This is finally how it should be.
Just to be sure, I went back to the Settings on the simulator and reset language to English (US) and region to United States. I commented out the
Finally, I went back to the Scheme and reset language and region to their original settings. Now everything was back to US and English. Adding the extension again set everything back to Dutch.
To me it seems that settings in the Scheme override those on the simulator (makes sense to me), and that extending NSLocale as I did overrides that again. It also seems to me that both Settings and Scheme do not affect the language, only the region.
For completeness, I also connected my iPhone and ran the app there. No difference with the simulator. App would only use Dutch language if forced to to so by the NSLocale extension, regardless of my iPhone settings, which are Dutch and Netherlands.
This leaves me with the following questions:
Do others have the same experience? Am I missing something obvious? Any insights will be greatly appreciated!
In Xcode check your
Thanks for replying.
I did as you suggested. It made no difference. Details follow.
Product\Option Run settings showed Dutch/Netherlands. I reset them to System Language/System Region.
The settings in the simulator are still Dutch/Netherlands. The Locale extension is commented out. Running the simulation gives:
Then setting the settings in the simulator to English/United States gives
Reactivating the extension gives again the desired result:
I rechecked the Product\Option Run settings, still System Language/System Region.
In summary, no difference it seems.
Just to be sure, I change the settings in the simulator by pressing the home button (simulating an iPhone 8) and going to Settings, General, Language & Region. Then I restart the simulation from XCode by cmd-R plus Replace.
SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.