Created
July 12, 2019 21:19
-
-
Save hngkr/a8cbc0b81fea37c5f1a80d756135a905 to your computer and use it in GitHub Desktop.
specific_locale context manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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