scripts/gestion/mail/locale_util.py
2014-10-22 00:06:14 +02:00

24 lines
614 B
Python

# -*- coding: utf-8 -*-
# Source:
# http://stackoverflow.com/questions/18593661/how-do-i-strftime-a-date-object-in-a-different-locale
import locale
import threading
from datetime import datetime
from contextlib import contextmanager
LOCALE_LOCK = threading.Lock()
@contextmanager
def setlocale(name):
with LOCALE_LOCK:
saved = locale.setlocale(locale.LC_ALL)
try:
yield locale.setlocale(locale.LC_ALL, name)
except:
yield saved
print "Warning: Failed setting locale %r" % name
finally:
locale.setlocale(locale.LC_ALL, saved)