[Qgis-user] localisation of date fails in QGIS 3.2

Frank Broniewski hallo at frankbroniewski.com
Thu Aug 9 01:03:55 PDT 2018


Hi Reginald,

 

I couldn’t find the post where you describe your problem. I just tried your code, this is the result from QGIS 3.2 (Windows) Python console, auto-locale German Germany (de_DE):

import datetime

vandaag = datetime.datetime.now() 

dag = vandaag.day 

maand = vandaag.strftime("%B") 

jaar = vandaag.year 

datum = str(dag) + " " + maand + " " + str(jaar)

print(datum)

9 August 2018

 

*but* when I override the locale to nl_BE I still get the same output as with the auto-locale.

 

import locale

print(locale.getlocale())

(None, None)

 

So I believe the locale is somehow not determinable for Python and a fallback is used.

 

Doing :

import locale

print(locale.getlocale())

(None, None)

locale.setlocale(locale.LC_ALL, 'nl_BE')

'nl_BE'

print(locale.getlocale())

('nl_BE', 'ISO8859-1')

import datetime

vandaag = datetime.datetime.now() 

dag = vandaag.day 

maand = vandaag.strftime("%B") 

jaar = vandaag.year 

datum = str(dag) + " " + maand + " " + str(jaar)

print(datum)

9 augustus 2018

 

does the trick though. There should be a way to get the set locale from PyQGIS somehow though …

 

Hth,

Frank

 

Von: Qgis-user <qgis-user-bounces at lists.osgeo.org> Im Auftrag von Reginald Carlier
Gesendet: Donnerstag, 9. August 2018 08:40
An: Nyall Dawson <nyall.dawson at gmail.com>; 'qgis-user at lists.osgeo.org' <qgis-user at lists.osgeo.org>
Betreff: Re: [Qgis-user] localisation of date fails in QGIS 3.2

 

Hi Nyall,

Somehow my post shows the code but my previous post doesn't.
Anyway this is how the code looks:

vandaag = datetime.now() 
dag = vandaag.day 
maand = vandaag.strftime("%B") 
jaar = vandaag.year 
datum = str(dag) + " " + maand + " " + str(jaar)

I suspect that maybe strftime changed in python 3.6?

Regards,





Reginald Carlier​



Deskundige GIS



 <https://www.ingelmunster.be/> 




Gemeente Ingelmunster

, 

Oostrozebekestraat 4

, 

8770

 

Ingelmunster




T

 <tel:+32%2051%2033%2074%2039> +32 51 33 74 39


 <http://www.ingelmunster.be/> www.ingelmunster.be




 <https://www.facebook.com/Ingelmunster/> 

 <https://www.instagram.com/ingelmunster/> 

 <https://www.pinterest.com/ingelmunster/> 

 <https://twitter.com/ingelmunster> 


 <http://www.ingelmunster.be/email-disclaimer.html> Raadpleeg onze disclaimer 

-----Oorspronkelijk bericht-----
Van: Nyall Dawson [mailto:nyall.dawson at gmail.com] 
Verzonden: donderdag 9 augustus 2018 8:36
Aan: Reginald Carlier
CC: qgis-user
Onderwerp: Re: [Qgis-user] localisation of date fails in QGIS 3.2

On Mon, 30 Jul 2018 at 19:22, Reginald <Reginald.Carlier at ingelmunster.be <mailto:Reginald.Carlier at ingelmunster.be> > wrote:
>
> Hi,
>
> I have a script that was adapted to python 3.6 and runs fine on QGIS 3.2.
> The problem I'm having is that the date shows up in english.
> Under Extra > Options > Algemeen i have:
> Vertaling gebruikers-interface --> Nederlands
> Locale Dutch Belgium (nl_BE)
>
> Also if I choose for "Systeemlocale negeren" (ignore system locale) I still
> get the date in english.
> My code looks like this and works fine in QGIS 2.18:
>
>

I think you forgot to include the code? Can you re-share?

Nyall

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20180809/1c7cfea6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5488 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20180809/1c7cfea6/attachment.bin>


More information about the Qgis-user mailing list