Created
May 6, 2013 08:44
-
-
Save dwt/5524039 to your computer and use it in GitHub Desktop.
Workaround for the inability of TranslationString to combine multiple TranslationStrings
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
from pyramid.i18n import TranslationStringFactory | |
_ = TranslationStringFactory('yeepa') | |
def _get_localizer(): | |
from pyramid.i18n import get_localizer, make_localizer | |
from pyramid.threadlocal import get_current_request | |
if get_current_request(): | |
# pyramid context | |
return get_localizer(get_current_request()) | |
else: | |
# most likely tornado context, may also be cron or whatever | |
from yeepa.gameserver.application import configuration | |
# relying on the fact that this is memoized and initialized correctly from the first call. | |
config = configuration() | |
locale_name = config.get('app:yeepa_backend', 'pyramid.default_locale_name') | |
import pkg_resources | |
translation_dir = pkg_resources.resource_filename('yeepa', 'locale') | |
return make_localizer(locale_name, [translation_dir]) | |
def translate_immediately(a_string): | |
localizer = _get_localizer() | |
return localizer.translate(_(a_string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment