My take on getting the locale from Qt and setting it in Python:
import locale
def get_qgis_locale():
loc = QLocale()
for lang in loc.uiLanguages():
if lang.startswith(loc.bcp47Name()):
return '%s.UTF-8' % lang.replace('-', '_')
return 'en_US.UTF-8'
locale.setlocale(locale.LC_ALL, get_qgis_locale())
print(locale.getlocale())
uiLanguages() is a bit ambiguous, when using auto locale it just shows ‘de’ for
me, setting
the override – not the user interface – to nl_BE it shows ‘nl-BE’ which should
be enough for setting locale.setlocale, you just need to replace the dash with
an underscore. There is still the possibility that this will break on some
language combinations though.
Frank
Von: Qgis-user <[email protected]> Im Auftrag von Alessandro
Pasotti
Gesendet: Donnerstag, 9. August 2018 09:30
An: Reginald Carlier <[email protected]>
Cc: [email protected]
Betreff: Re: [Qgis-user] localisation of date fails in QGIS 3.2
On Thu, Aug 9, 2018 at 9:23 AM, Reginald Carlier
<[email protected] <mailto:[email protected]> >
wrote:
Thanks a lot Alessandro,
That works perfectly.
Glad it helped.
btw, this is a side-effect of the recent changes in QGIS locale: we are now
using setting a "default locale" (from QGIS settings) when QGIS starts, and
that locale is used through the whole QGIS application.
If you change the default locale in the settings, please remember to restart
QGIS.
Reginald Carlier
Deskundige GIS
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Gemeente Ingelmunster
<https://www.ingelmunster.be/> ,
<https://www.ingelmunster.be/> Oostrozebekestraat 4
<https://www.ingelmunster.be/> ,
<https://www.ingelmunster.be/> 8770
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Ingelmunster
<https://www.ingelmunster.be/> T
<https://www.ingelmunster.be/> +32 51 33 74 39
<https://www.ingelmunster.be/> www.ingelmunster.be
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Raadpleeg onze disclaimer
<https://www.ingelmunster.be/> Van: Alessandro Pasotti
[mailto:[email protected]]
Verzonden: donderdag 9 augustus 2018 9:10
Aan: Reginald Carlier
CC: Nyall Dawson [via OSGeo.org]; [email protected]
Onderwerp: Re: [Qgis-user] localisation of date fails in QGIS 3.2
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Reginald,
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Using QT:
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> locale = QLocale(QLocale.Japanese)
<https://www.ingelmunster.be/> locale.toString(QDate.currentDate())
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> And, if you want to use the same settings that
you set in QGIS, just use the default locale:
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> locale = QLocale() # Default locale from QGIS
options/settings
<https://www.ingelmunster.be/> locale.toString(QDate.currentDate())
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> On Thu, Aug 9, 2018 at 8:54 AM, Reginald
Carlier <[email protected]> wrote:
<https://www.ingelmunster.be/> I forgot to mention that I import datetime as
follows:
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> from datetime import datetime
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> In the console I get the same result as from my
script.
<https://www.ingelmunster.be/> Maybe I should use QCoreApplication.translate
or some other explicit way to tell python to translate a string from English to
Dutch?
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Regards,
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Reginald Carlier
<https://www.ingelmunster.be/> Deskundige GIS
<https://www.ingelmunster.be/> Fout! Bestandsnaam niet opgegeven.
<https://www.ingelmunster.be/> Gemeente Ingelmunster
<https://www.ingelmunster.be/> ,
<https://www.ingelmunster.be/> Oostrozebekestraat 4
<https://www.ingelmunster.be/> ,
<https://www.ingelmunster.be/> 8770
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> Ingelmunster
<https://www.ingelmunster.be/> T
<https://www.ingelmunster.be/> +32 51 33 74 39
<https://www.ingelmunster.be/> www.ingelmunster.be
<https://www.ingelmunster.be/> Fout! Bestandsnaam niet opgegeven.
<https://www.ingelmunster.be/> Fout! Bestandsnaam niet opgegeven.
<https://www.ingelmunster.be/> Fout! Bestandsnaam niet opgegeven.
<https://www.ingelmunster.be/> Fout! Bestandsnaam niet opgegeven.
<https://www.ingelmunster.be/> Raadpleeg onze disclaimer
<https://www.ingelmunster.be/> Van: Nyall Dawson [via OSGeo.org]
[mailto:[email protected]]
Verzonden: donderdag 9 augustus 2018 8:43
Aan: Reginald Carlier
Onderwerp: Re: localisation of date fails in QGIS 3.2
<https://www.ingelmunster.be/>
<https://www.ingelmunster.be/> On Thu, 9 Aug 2018 at 16:39, Reginald Carlier
<[hidden email]> wrote:
<https://www.ingelmunster.be/>
>
> 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?
<https://www.ingelmunster.be/>
Do you see the same from a standalone python console? (I'm not sure
that this issue is related to QGIS at all or whether it's a Python
specific thing).
Nyall
_______________________________________________
Qgis-user mailing list
[hidden email]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
<https://www.ingelmunster.be/>
_____
<https://www.ingelmunster.be/> If you reply to this email, your message will
be added to the discussion below:
<https://www.ingelmunster.be/>
http://osgeo-org.1560.x6.nabble.com/localisation-of-date-fails-in-QGIS-3-2-tp5372703p5373899.html
<https://www.ingelmunster.be/> To start a new topic under QGIS - User, email
[email protected]
To unsubscribe from QGIS, click here.
NAML
<https://www.ingelmunster.be/>
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
<https://www.ingelmunster.be/>
--
<https://www.ingelmunster.be/> Alessandro Pasotti
w3: www.itopen.it
<https://www.ingelmunster.be/>
--
<https://www.ingelmunster.be/> Alessandro Pasotti
w3: www.itopen.it
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Qgis-user mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-user Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
