Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a temporary_locale context manager #1347

Closed
smartass101 opened this issue May 13, 2014 · 7 comments · Fixed by #3224
Closed

Use a temporary_locale context manager #1347

smartass101 opened this issue May 13, 2014 · 7 comments · Fixed by #3224

Comments

@smartass101
Copy link
Contributor

While working on my i18n_subsites plugin, I came up with an idea how to simplify some code that is often used in Pelican: doing stuff with a temporarily different locale.
This could be neatly solved by a context manager:

from contextlib import contextmanager
import locale

@contextmanager
def temporary_locale(temp_locale=None):
    '''Enable code to run in a context with a temporary locale

    Resets the locale back when existing context.
    Can set a temporary locale if provided
    '''
    orig_locale = locale.setlocale(locale.LC_ALL)
    if temp_locale is not None:
        locale.setlocale(locale.LC_ALL, temp_locale)
    yield
    locale.setlocale(locale.LC_ALL, orig_locale)

This would enable stuff like

with temporary_locale('C'):
     pass
@smartass101 smartass101 added this to the 3.5 milestone May 13, 2014
@smartass101 smartass101 self-assigned this May 13, 2014
@justinmayer justinmayer modified the milestones: 3.4.1, 3.5 Aug 13, 2014
@justinmayer
Copy link
Member

@smartass101: Seems like a sensible idea. Would you like to work on this for the upcoming 3.5 release?

@justinmayer justinmayer modified the milestones: 3.6, 3.7 Feb 17, 2015
@justinmayer
Copy link
Member

@smartass101: Any update on your proposal here?

@justinmayer justinmayer removed this from the 3.7 milestone Oct 22, 2016
@usmanatron
Copy link

Im going to pick this up; looks like a good first issue to start contributing!

@justinmayer
Copy link
Member

@usmanatron: Any progress on your work on this issue?

Would anyone else like to implement the functionality described in this issue?

@justinmayer
Copy link
Member

@avaris: Would you mind sharing your thoughts on this proposal? Would be nice to close it out, one way or another.

@justinmayer justinmayer assigned avaris and unassigned smartass101 Apr 30, 2020
@justinmayer justinmayer removed the docs label May 16, 2020
@holden-nelson
Copy link

Submitted a pull request for this feature. Kind of a contributing noob so let me know if I did anything incorrectly or need to make any changes. Thanks!

@holden-nelson
Copy link

Ahh, now I see pull request #2027 which fixes the issue and implements the new functionality right away. Oh well! Would you like me to just close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment