Using the language class – switching language on the go

Once you have developed your site to accommodate multiple languages, you'll obviously want to allow people to switch between them. For example, to switch from English to French, or French to German, or whatever region or language you're developing for. This can be handled in several ways, but in this example, we're going to use the CodeIgniter Session class to swap from one language to another.

Getting ready

We're going to use the Session class to store the user's language preference, which means, we'll need to use CodeIgniter sessions. This will require some configuration.

We'll be editing the following files:

  • path/to/codeigniter/application/config/config.php
  • path/to/codeigniter/application/config/database.php ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.