예제 #1
0
def global_renderer(event):
    """Add localizer, and translation methods to context."""
    request = event["request"]
    set_localizer(request)

    event["_"] = request._
    event["localizer"] = request.localizer
예제 #2
0
    def reload_catalog(self):
        '''
            Reloads transation caalog for application it's run in.

            .. note::
                To see how is this happening, you might want to see :func:`~pyramid_localize.tools.set_localizer`

            :returns:

                Only for xhr requests:

                .. code-block:: python

                    {
                        'status': True,
                        'msg': 'Localizators has been reloaded' # translated
                    }

                non xhr requests: Redirects to **localize:index**.


        '''

        set_localizer(self.request, True)

        if self.request.is_xhr:
            return {'status': True, 'msg': self.request._('Localizators has been reloaded')}

        return HTTPFound(location=self.request.route_url('localize:index'))
예제 #3
0
def global_renderer(event):
    """Add localizer, and translation methods to context."""
    request = event['request']
    set_localizer(request)

    event['_'] = request._
    event['localizer'] = request.localizer
예제 #4
0
    def reload_catalogue(self):
        """
        Reload translation catalogue for application it's run in.

        .. note::

            To see how is this happening, you might want to see
            :func:`~pyramid_localize.tools.set_localizer`

        :returns:

            Only for xhr requests:

            .. code-block:: python

                {
                    'status': True,
                    'msg': 'Localizators has been reloaded' # translated
                }

            non xhr requests: Redirects to **localize:index**.


        """
        set_localizer(self.request, True)

        if self.request.is_xhr:
            return {'status': True, 'msg': self.request._('Localizators has been reloaded')}

        return HTTPFound(location=self.request.route_url('localize:index'))
예제 #5
0
def global_renderer(event):
    """Subscriber for BeforeRender, adds localizer, and translation methods to context."""
    request = event['request']
    set_localizer(request)

    event['_'] = request._
    event['localizer'] = request.localizer
예제 #6
0
def global_renderer(event):
    '''
        Subscriber, which extends variables available for renderer with translator method, and localizer object
    '''
    request = event['request']
    set_localizer(request)

    event['_'] = request._
    event['localizer'] = request.localizer
예제 #7
0
 def _makeRequest(self, environ=None):
     if environ is None:
         environ = {}
     request = Request(environ)
     request.registry = self.config.registry
     request.config = Mock()
     mock_configuration = {
         'localize.locales.available': ['en', 'pl', 'de', 'cz']}
     request.config.configure_mock(**mock_configuration)
     set_localizer(request)
     return request
예제 #8
0
 def test_reset(self):
     '''test resetting localizer capabilites'''
     request = self._makeRequest()
     old_localizer = request.localizer
     request_utility = request.registry.queryUtility(ILocalizer,
                                                     name=request.locale_name)
     self.assertEqual(request_utility, request.localizer)
     set_localizer(request, reset=True)
     # these are equal due to request.localizer
     # being reify property since pyramid 1.5
     self.assertEqual(old_localizer, request.localizer)
     # let's create a new request, to check that
     request = self._makeRequest()
     self.assertNotEqual(old_localizer, request.localizer)
예제 #9
0
def test_reset(web_request):
    """
    Test resetting localizer capabilites.

    1. localizer gets set on a request.
    2. Reset localizer call gets issued.
    3. New request have new localizer set.
    """
    # set (and create localizer)
    set_localizer(web_request)
    old_localizer = web_request.localizer

    queried_localizer = web_request.registry.queryUtility(
        ILocalizer, name=web_request.locale_name)
    assert queried_localizer == web_request.localizer
    # resetting localizer
    set_localizer(web_request, reset=True)
    # these are equal due to request.localizer
    # being reify property since pyramid 1.5
    assert old_localizer == web_request.localizer
    queried_localizer_after_reset = web_request.registry.queryUtility(
        ILocalizer, name=web_request.locale_name)

    assert queried_localizer_after_reset is not queried_localizer
    # let's create a new request, to check that
    request = web_request_func()
    set_localizer(web_request)
    assert old_localizer is not request.localizer
예제 #10
0
def test_reset(web_request):
    """
    Test resetting localizer capabilites.

    1. localizer gets set on a request.
    2. Reset localizer call gets issued.
    3. New request have new localizer set.
    """
    # set (and create localizer)
    set_localizer(web_request)
    old_localizer = web_request.localizer

    queried_localizer = web_request.registry.queryUtility(
        ILocalizer, name=web_request.locale_name)
    assert queried_localizer == web_request.localizer
    # resetting localizer
    set_localizer(web_request, reset=True)
    # these are equal due to request.localizer
    # being reify property since pyramid 1.5
    assert old_localizer == web_request.localizer
    queried_localizer_after_reset = web_request.registry.queryUtility(
        ILocalizer, name=web_request.locale_name)

    assert queried_localizer_after_reset is not queried_localizer
    # let's create a new request, to check that
    request = web_request_func()
    set_localizer(web_request)
    assert old_localizer is not request.localizer
예제 #11
0
def test_translate(web_request):
    """Simple test for translating method call."""
    msgid = 'Test message'
    set_localizer(web_request)
    assert msgid == web_request._(msgid)
예제 #12
0
def test_simple(web_request):
    """Simple localizer setting test on a request."""
    set_localizer(web_request)
    assert isinstance(web_request.localizer, Localizer)
    assert hasattr(web_request, '_')
예제 #13
0
def add_localizer(event):
    '''
        We add localzer for each new request (we use tools.set_localizer method, as to not repeat yourself)
    '''
    set_localizer(event.request)
예제 #14
0
def add_localizer(event):
    """Add localizer and translation methods to request."""
    set_localizer(event.request)
예제 #15
0
def add_localizer(event):
    """Subscriber for NewRequest, adds localizer and translation methods to request."""
    set_localizer(event.request)
예제 #16
0
def test_translate(web_request):
    """Simple test for translating method call."""
    msgid = 'Test message'
    set_localizer(web_request)
    assert msgid == web_request._(msgid)
예제 #17
0
def test_simple(web_request):
    """Simple localizer setting test on a request."""
    set_localizer(web_request)
    assert isinstance(web_request.localizer, Localizer)
    assert hasattr(web_request, '_')
예제 #18
0
def add_localizer(event):
    """Add localizer and translation methods to request."""
    set_localizer(event.request)