NSLocale localeIdentifier "en_DE"

Mac OSX specific forum
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

NSLocale localeIdentifier "en_DE"

Post by mk-soft »

Why do I get the localeIdentifier "en_DE" in the query. Shouldn't I get "de_DE" for German?

This way the NSDateFormatter does not work directly to set the correct language.

Code: Select all


Macro CocoaString(NSString)
  PeekS(CocoaMessage(0, NSString, "UTF8String"), -1, #PB_UTF8)
EndMacro

Procedure.s GetDateString(Date.s = "")
  Protected NSPool, NSDate, NSCurrentLocale, NSLocale, NSDateFormatter, NSString
  Protected r1.s
  
  NSPool = CocoaMessage(0, 0, "NSAutoreleasePool new")
  
  NSDateFormatter = CocoaMessage(0, 0, "NSDateFormatter new")
  
  If Date = ""
    NSDate = CocoaMessage(0, 0, "NSDate date")
  Else
    CocoaMessage(0, NSDateFormatter, "setDateFormat:$", @"YYYYMMdd")
    NSDate = CocoaMessage(0, NSDateFormatter, "dateFromString:$", @Date)
    If Not NSDate
      Goto end_function
    EndIf  
  EndIf
  
  NSCurrentLocale = CocoaMessage(0, 0, "NSLocale currentLocale")
  NSString = CocoaMessage(0, NSCurrentLocale, "localeIdentifier")
  
  ;Debug CocoaString(NSString)
  
  If CocoaString(NSString) = "en_DE"
    NSLocale = CocoaMessage(0, 0, "NSLocale localeWithLocaleIdentifier:$", @"de_DE")
  Else
    NSLocale = NSCurrentLocale
  EndIf
  CocoaMessage(0, NSString, "release")
  
  CocoaMessage(0, NSDateFormatter, "setLocale:@", @NSLocale)
  CocoaMessage(0, NSDateFormatter, "setDateFormat:$", @"EEEE d MMMM YYYY") 
  NSString = CocoaMessage(0, NSDateFormatter, "stringFromDate:@", @NSDate)
  r1 = CocoaString(NSString)
  
  end_function:
  CocoaMessage(0, NSDateFormatter, "release")
  CocoaMessage(0, NSPool, "release")
  
  ProcedureReturn r1
EndProcedure

Debug GetDateString()
Debug GetDateString("19700101")
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
Shardik
Addict
Addict
Posts: 1984
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: NSLocale localeIdentifier "en_DE"

Post by Shardik »

mk-soft wrote:Why do I get the localeIdentifier "en_DE" in the query. Shouldn't I get "de_DE" for German?
I also had to find out that since Mojave the locale indentifier for German is reported as "en-DE" instead of "de_DE". It seems to be caused by a modification from Apple which is reported by a user for locale identifier "fr_CA" (Canadian french) in this stackexchange posting.

I have done my own tests with this small test code:

Code: Select all

MessageRequester("Current locale identifier:",
  PeekS(CocoaMessage(0, CocoaMessage(0, CocoaMessage(0, 0,
  "NSLocale currentLocale"), "localeIdentifier"), "UTF8String"), -1, #PB_UTF8))
And the tests indeed indicate that the locale identifier reported by the method currentLocale has changed from High Sierra to Mojave (tested with PB 5.73 x64):

en_DE in MacOS 11.2.1 'Big Sur'
en_DE in MacOS 10.15.7 'Catalina'
en_DE in MacOS 10.14.6 'Mojave'
de_DE in MacOS 10.13.6 'High Sierra'
de_DE in MacOS 10.12.6 'Sierra'
User avatar
mk-soft
Always Here
Always Here
Posts: 5313
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: NSLocale localeIdentifier "en_DE"

Post by mk-soft »

This is not good, because then a separate NSLocale has to be created every time it is required. As with NSDateFormatter
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply