Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
4453 Näkymät

I have set a report line as:

o.scheduled_date.strftime('%A, %d-%m-%Y, a las %H:%M')" style="color:red; font-size:24px;"/>

Everything is ok but the output day of the week is in English, I would like it in Spanish.

Tuesday 25/01/2022, a las 14:30 in place of Martes 25/01/2022 a las 14:30

Any idea in how to incorporate LOCALE to the field?

Thanks

Avatar
Hylkää
Paras vastaus



In  Py


def locale_date(self,scheduled_date):
    if scheduled_date:
        loc = locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
        return scheduled_date.strftime('%A, %d-%m-%Y, a las %H:%M')


Hope it Helps,

Kiran K

Avatar
Hylkää

In XML
<span t-esc="o.locale_date(o.scheduled_date)"/>

Tekijä

Thanks. It would change time_zone, but what i need is to change language to Spanish for de day of the week. So, Lunes in place of Monday.

It will change day also,
Output

Before - Wednesday, 26-01-2022, a las 09:58
After - Mittwoch, 26-01-2022, a las 09:58

Tekijä

Thanks a lot Kiran.
I use the XML option. How to define locale.setlocale y xml?

i need definition before p t-esc as follows

<p t-esc="o.locale_date(o.scheduled_date).strftime('%A, %d-%m-%Y, a las %H:%M')" style="color:red; font-size:24px;"/>

Write a method in py to set locale, Function called from XML with the date as a parameter and returned it after converting

In XML

<p t-esc="o.locale_date(o.scheduled_date)" style="color:red; font-size:24px;"/>

In Py

def locale_date(self,scheduled_date):
if scheduled_date:
loc = locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
return scheduled_date.strftime('%A, %d-%m-%Y, a las %H:%M')

Tekijä

Thanks a lot Kiran. I am trying to do it just in developer mode. So, no py involved

Paras vastaus

Thanks for the answer.s

Avatar
Hylkää
Paras vastaus

I want to know how to set LOCALE in time format for PDF

Avatar
Hylkää

Hi Francisca Ezell,

Try,

In XML

<p t-esc="o.locale_date(o.scheduled_date)" style="color:red; font-size:24px;"/>

In Py

def locale_date(self,scheduled_date):
if scheduled_date:
loc = locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
return scheduled_date.strftime('%A, %d-%m-%Y, a las %H:%M')

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 25
1601
3
heinäk. 25
3249
1
toukok. 25
1389
1
toukok. 25
1639
4
toukok. 25
2806