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

I'm modifing a module to get the full month (translated) instead of Y/m/d:

old: new_date.strftime('%Y-%m-%d')

new: new_date.strftime('%B')

%B gives the full month in english, how can I translate the month in the current Odoo language setting using python code (not qweb)?


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

import locale


# Change timelocale to current account's language setting in Odoo.

locale.setlocale(locale.LC_TIME, self.env.context['lang'] + '.utf8')


# example (hardcoded) for dutch:

# locale.setlocale(locale.LC_TIME, 'nl_NL.utf8')


# proof of concept

from datetime import datetime

new_date = datetime.now()

new_date.strftime('%B')

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 12 23
44756
1
thg 11 23
1123
2
thg 3 16
3392
1
thg 3 15
7671
2
thg 5 22
16087