O'Reilly logo

CakePHP 1.3 Application Development Cookbook by Mariano Iglesias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Translating strings with dynamic content

In this recipe, we will learn how to allow strings consisting of parts that are not static, such as variable values, to be translatable.

Getting ready

To go through this recipe, we need a basic application skeleton to work with. Go through the entire recipe Internationalizing controller and view texts.

How to do it...

  1. Edit the file articles_controller.php located in your app/controllers folder and make the following changes to the add() method:
    public function add() {
    if (!empty($this->data)) {
    $this->Article->create();
    if ($this->Article->save($this->data)) {
    $this->Session->setFlash(
    sprintf(__('Article "%s" saved', true), $this->Article->field('title')) ); $this->redirect(array('action'=>'index')); } else ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required