Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4467 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất



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

Ảnh đại diện
Huỷ bỏ

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

Tác giả

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

Tác giả

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

Tác giả

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

Câu trả lời hay nhất

Thanks for the answer.s

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 6 25
1609
3
thg 7 25
3254
1
thg 5 25
1395
1
thg 5 25
1644
4
thg 5 25
2812