for lang in lang_codes:
    locale.setlocale(lang)
time_format[lang] = locale.nl_langinfo(locale.D_FMT)
How do I get the correct date format string for a given locale without setting that locale program-wide in Python?