-
Notifications
You must be signed in to change notification settings - Fork 8
Cabeçalho Accept Language
Guilherme Nascimento edited this page Jul 30, 2019
·
4 revisions
Veja mais detalhes sobre negociação de conteudo em Negociação de Conteúdo HTTP
Carregando configurações de um idioma especifico:
<?php
use Inphinit\App;
use Inphinit\Routing\Route;
use Inphinit\Experimental\Config;
use Inphinit\Experimental\Http\Negotiation;
Route::set('GET', '/foobar', function () {
$negotiation = new Negotiation;
$langs = $negotiation->acceptLanguage();
$langConfig = null;
$currentLang = null;
foreach ($langs as $lang) {
try {
$langConfig = Config::load(sprintf('i8n.%s', $lang['value'])); //lê configurações da pasta `./system/application/Config/i8n/`
$currentLang = $lang['value'];
break;
} catch (Exception $ee) {}
}
if (!$currentLang) {
App::stop(406, 'Not Acceptable');
}
...
});
Customizando view:
<?php
use Inphinit\App;
use Inphinit\Viewing\View;
use Inphinit\Routing\Route;
use Inphinit\Experimental\Http\Negotiation;
Route::set('GET', '/foobar', function () {
$negotiation = new Negotiation;
$langs = $negotiation->acceptLanguage();
$availableLangs = array( 'pt-br', 'en' );
$currentLang = null;
foreach ($langs as $lang) {
if (in_array($lang['value'], $availableLangs)) {
$currentLang = $lang['value'];
break;
}
}
switch ($currentLang)
{
case 'pt-BR':
case 'pt-PT':
case 'pt':
$values = array(
'title' => 'Olá mundo!',
'description' => 'Seja bem vindo'
);
break;
case 'de':
$values = array(
'title' => 'Hallo Welt!',
'description' => 'Herzlich willkommen'
);
break;
default:
App::stop(406, 'Not Acceptable');
}
View::render('example', $values);
});
Custom view from Inphinit\Experimental\Config
:
<?php
use Inphinit\App;
use Inphinit\Viewing\View;
use Inphinit\Routing\Route;
use Inphinit\Experimental\Config;
use Inphinit\Experimental\Http\Negotiation;
Route::set('GET', '/foobar', function () {
$negotiation = new Negotiation;
$langs = $negotiation->acceptLanguage();
$currentLang = null;
foreach ($langs as $lang) {
try {
$langConfig = Config::load(sprintf('i8n.%s', $lang['value'])); //lê configurações da pasta `./system/application/Config/i8n/`
$currentLang = $lang['value'];
break;
} catch (Exception $ee) {}
}
if (!$currentLang) {
App::stop(406, 'Not Acceptable');
}
View::render('example', array(
'title' => $langConfig->title,
'description' => $langConfig->description
));
});
Inphinit the PHP Framework is writed using PSR-1, PSR-2 and PSR-4, you can use Controllers, Views, Routes
- Getting Started
- About
- Performance
- Directory Structure
- Constants
- Routing
- Controllers
- Views
- Events
- HTTP Response
- HTTP Request
- HTTP Redirect
- HTTP Content Negotiation
- Storage and Files
- Rest
- Maintenance
- Regular Expression
- Response Cache
- DOM, XML, HTML, JSON and Arrays
- QuerySelector (CSS-selectors) with PHP
- Configuration
- Instalação
- Sobre
- Desempenho
- Estrutura das pastas
- Constantes
- Rotas
- Usando Controllers
- Usando Views
- Eventos
- Resposta HTTP
- Requisição HTTP
- Redirecionamento HTTP
- Negociação de Conteúdo HTTP
- Armazenamento e Arquivos
- Usando Rest
- Manutenção
- Expressão Regular
- Cache Resposta
- DOM, XML, HTML, JSON e Arrays
- QuerySelector (seletores-CSS) com PHP
- Configuração