2017 © Pedro Peláez
 

library stack-localize

A stack middleware for detecting URI locales.

image

frenzy/stack-localize

A stack middleware for detecting URI locales.

  • Saturday, May 17, 2014
  • by yuters
  • Repository
  • 2 Watchers
  • 3 Stars
  • 432 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Frenzy/Localize

This stack middleware gives localization features to your application. It will start looking for the locale in the URL. If none is present, it will default to the one you provide., (*1)

No default will result in getting the HTTP_ACCEPT_LANGUAGE from the user and try to match it to an available locale., (*2)

This middleware can detect language specified on a URI prefix. ex.:, (*3)

http://mydomain.com/en
http://mydomain.com/fr

The locale will be accessible on the Request getLocale() method and be removed from the request pathinfo for easier routing., (*4)

Example with Silex

<?php

require_once __DIR__.'/../vendor/autoload.php';

use Symfony\Component\HttpFoundation\Request;

$app = new Silex\Application();

// Accessible on /{locale}/
$app->get('/', function (Request $request) {
    // The locale should be set.
    return $request->getLocale();
});

// Accessible on /{locale}/test
$app->get('/test', function (Request $request) {
    // The locale should be set.
    return $request->getLocale().'/test';
});

$locales = ['en', 'fr', 'es'];
$fallback = 'en';
$redirectDefault = true;

$stack = new Stack\Builder();
$stack->push('Frenzy\Localize\StackLocalize', $locales, $fallback, $redirectDefault);
$app = $stack->resolve($app);

$request  = Request::createFromGlobals();
$response = $app->handle($request)->send();

$app->terminate($request, $response);

Example with Laravel

<?php

$params = [
    'locales' => ['fr', 'en', 'es'],
    'fallback' => 'fr',
    'redirectDefault' => true,
];

App::middleware('Frenzy\Localize\StackLocalize', $params);

// Be sure to set the locale from the request when booting your app.
App::setLocale(Request::getLocale());

TODO

  • Tests

The Versions

17/05 2014

dev-master

9999999-dev

A stack middleware for detecting URI locales.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Bastien

middleware stack locale localization