Languages (i18n)

Don't forget to read this

Using languages in Twig

Sample

PHP (Controller):

public function index( $request, $response ) {
    return $this->view->render( $response, 'home.twig', array(
        'response' => $response,
        'page'     => array(
            'title'        => 'Johnny Remember me',
            'body_classes' => 'joepie',
            'route'        => '#',
            'ip' => $request->getAttribute('ip_address'),
            'metadata'     => array(
                [ 'name' => 'johan', 'content' => 'van de merwe' ],
                [ 'name' => 'marga', 'content' => 'van de merwe-toma' ]
            ),
            'content'      => array(
                'header' => __( 'It really works' ),
                'body'   => __( 'This is a nice text to sum things up' )
            )
        )
    ));
}

Twig:

{% block content %}
    <div class="container">
        <div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <span class="fa fa-cog"></span> {{ page.content.header }}
                    </div>
                    <div class="panel-body">{{ page.content.body }}</div>
                </div>
            </div>
            <div class="col-md-4">
                <div>
                    <p>{{ _n('1 house', '% houses', 2) }}</p>
                    <p>{{ _n('1 house', '% houses', 1) }}</p>
                    <p>{{ __('A very nice text') }}</p>
                    <p>{{ __('A text (with parenthesis)') }}</p>
                    <p>{{ __('A text "with double quotes"') }}</p>
                    <p>{{ __('A text \'with escaped single quotes\'') }}</p>
                    <p>{{ page.ip }}</p>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

As the sample shows there are a 2 ways to access the language dependent features in this Slim framework fork.

Last update: March 15th at 9:45am