sahama / pyramid_i18n_helper

helper to create new smgid and translate msgid to local langs
3 stars 2 forks source link

do not use globals #1

Closed mmerickel closed 7 years ago

mmerickel commented 7 years ago

Instead of pyramid_i18n_helper.root_package_directory and .root_package_name you could store these values in the application registry such that the helper can be used for multiple apps in the same process. This is a simple fix.

from pyramid.decorator import reify

class I18NHelper(object):
    def __init__(self, package):
        self.package = package

    @reify
    def package_dir(self):
        return os.path.abspath(os.path.dirname(config.root_package.__file__))

    @reify
    def package_name(self):
        return os.path.basename(config.root_package.__file__)

def includeme(config):
    config.registry['i18n_helper'] = I18NHelper(config.root_package)

def some_view(request):
    helper = request.registry['i18n_helper']
sahama commented 7 years ago

I fixed it. Thanks