It is currently Tue Mar 09, 2021 11:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: NSLocale localeIdentifier "en_DE"
PostPosted: Sat Feb 20, 2021 2:27 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2892
Location: Germany
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:

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 / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: NSLocale localeIdentifier "en_DE"
PostPosted: Sun Feb 21, 2021 5:22 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1814
Location: Germany
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:
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'


Top
 Profile  
Reply with quote  
 Post subject: Re: NSLocale localeIdentifier "en_DE"
PostPosted: Sun Feb 21, 2021 9:22 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2892
Location: Germany
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 / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye