Code Monkey home page Code Monkey logo

translation's Introduction

Validus Translation

Provides translations for zend expressive projects.

SensioLabsInsight


Packagist GitHub license Build Status Scrutinizer Code Quality Code Intelligence Status Coverage Status


Symfony Translation factories for PSR-11 with Zend configuration provider.

Installation

The easiest way to install this package is through composer:

$ composer require validus/translation

Configuration

A complete example configuration can be found in example/full-config.php. Please note that the values in there are the defaults, and don't have to be supplied when you are not changing them. Keep your own configuration as minimal as possible. A minimal configuration can be found in example/simple-config.php

If your application uses the zend-component-installer Composer plugin, your configuration is complete; the shipped Validus\Translation\ConfigProvider registers the translation service.

Usage

Validus Translation provides middleware consuming PSR-7 HTTP message instances, via implementation of PSR-15 interfaces.

Adding the middleware to your application

you may pipe this middleware anywhere in your application. If you want to have it available anywhere, pipe it early in your application, prior to any routing. As an example, within Expressive, you could pipe it in the config/pipeline.php file:

$app->pipe(\Validus\Translation\Middleware\TranslatorMiddleware::class);

Within Expressive, you can do this when routing, in your config/routes.php file, or within a delegator factory:

$app->post('/login', [
    \Validus\Translation\Middleware\TranslatorMiddleware::class,
    \User\Middleware\LoginHandler::class
]);

Accessing the translator

if you have added the middleware to your application, you can access the translator from the request attributes :

     public function handle(ServerRequestInterface $request): ResponseInterface
     {
        $translator = $request->getAttribute(TranslatorMiddleware::TRANSLATOR_ATTRIBUTE);
        // or simply 
        $translator = $request->getAttribute('translator');
        
        // do your thing 
        
        return $response;
     }

or via the container :

use Symfony\Component\Translation\TranslatorInterface;

$translator = $container->get(TranslatorInterface::class);

translation's People

Contributors

azjezz avatar stickler-ci avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.