Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
28226 Vues

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


Avatar
Ignorer
Meilleure réponse

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

Avatar
Ignorer
Publications associées Réponses Vues Activité
3
déc. 23
44861
1
nov. 23
1143
2
mars 16
3411
1
mars 15
7688
2
mai 22
16129