Skip to content

Instantly share code, notes, and snippets.

@hngkr
Created July 12, 2019 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hngkr/a8cbc0b81fea37c5f1a80d756135a905 to your computer and use it in GitHub Desktop.
Save hngkr/a8cbc0b81fea37c5f1a80d756135a905 to your computer and use it in GitHub Desktop.
specific_locale context manager
import contextlib
import locale
@contextlib.contextmanager
def specific_locale(category, locale_string):
prev_locale_string = locale.getlocale(category)
locale.setlocale(category, locale_string)
try:
yield
finally:
locale.setlocale(category, prev_locale_string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment