跳至內容
選單
此問題已被標幟
1 回覆
28473 瀏覽次數

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


頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
12月 23
45237
1
11月 23
1286
2
3月 16
3560
1
3月 15
7856
2
5月 22
16315