2017 © Pedro Peláez
 

library multilingualslim

Multilanguage support for Slim framework 3

image

luism-s/multilingualslim

Multilanguage support for Slim framework 3

  • Sunday, January 29, 2017
  • by luism-s
  • Repository
  • 1 Watchers
  • 2 Stars
  • 64 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Multilingual Slim

Extension to the Slim framework v3 to enable language based routing, i.e. i18n and l10n., (*1)

Dependencies

Installation

By terminal:, (*2)


composer require luism-s/multilingualslim "dev-master"

By editing composer.json, (*3)


{ "require": { "luism-s/multilingualslim": "dev-master" } }

Usage

The $container is used as an interface between the Middleware and the Routes. The multilinguage middleware injects the following variables into the $container: default_language, available_languages and language. The first two are variables set by the developer, and the last is set by the middleware itself and indicates the requested language., (*4)


use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; require '../vendor/autoload.php'; $default_language = 'pt'; $available_languages = ['pt', 'en']; $app = new \Slim\App(); $container = $app->getContainer(); $app->add( new \MultilingualSlim\LanguageMiddleware($available_languages, $default_language, $container) ); $app->get('/', function (Request $request, Response $response) { //This works with '/', '/pt' and '/en', //and prints 'Hello' in each language. if ($this->language === 'pt') { return $response->write("Olá Mundo"); } elseif($this->language === 'en') { return $response->write("Hello World"); } }); $app->run();

You can also use a library to render templates such as php-view. For example:, (*5)


$container['renderer'] = new \Slim\Views\PhpRenderer("../views/"); $app->get('/home', function (Request $request, Response $response) { //This works with '/home', '/pt/home' and '/en/home', //and returns the template views/base.php. //It also passes the chosen language as an argument accessible from the chosen template. return $this->renderer->render($response, "base.php", [ "language" => $this->language ]); });

Acknowledgements

This project is largely influenced by SimoTod/slim-multilanguage, which follows the same philosophy but is made for the version 2 of Slim., (*6)

TODO

Develop functions to do things such as testing for default language, get current language, compare language, and maybe more., (*7)

The Versions

29/01 2017

dev-master

9999999-dev https://github.com/luism-s/MultilingualSlim

Multilanguage support for Slim framework 3

  Sources   Download

MIT

The Requires

 

i18n slim multilingual multilanguage l10n

31/10 2016

v1.1

1.1.0.0 https://github.com/luism-s/MultilingualSlim

Multilanguage support for Slim framework 3

  Sources   Download

MIT

The Requires

 

i18n slim multilingual multilanguage l10n

30/10 2016

v1.0

1.0.0.0 https://github.com/luism-s/MultilingualSlim

Multilanguage support for Slim framework 3

  Sources   Download

MIT

The Requires

 

i18n slim multilingual multilanguage l10n