This question has been flagged
3 Replies
2603 Views

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
Discard
Best Answer



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
Discard

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

Author

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

Author

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')

Author

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

Best Answer

Thanks for the answer.s

Avatar
Discard
Best Answer

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

Avatar
Discard

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')