In this recipe, we will learn how to allow users to change the current language and have their language selection be remembered through the use of cookies.
To go through this recipe we need a fully internationalized application to work with. Go through the entire recipe Translating database records with the Translate behavior.
We also need an application layout that we can modify. Copy the file default.ctp
from cake/libs/view/layouts
to your app/views/layouts
directory.
1. Edit your
app/config/bootstrap.php
file and add the following right above the PHP closing tag:Configure::write('Config.languages', array( 'eng' => __('English', true), 'spa' => __('Spanish', true) ));
2. Edit the
default.ctp
layout file located in yourapp/views/layouts
folder and add the following where you want the list of languages to be included (such as right above the call to theflash()
method of theSession
component):<div style="float: right...