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 yourapp/controllers
folder and make the following changes to theadd()
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 { $this->Session->setFlash('Please correct the errors'); } } }
2. Edit the view file
index.ctp
located in yourapp/views/articles
folder and make the following changes:<h1><?php __('Articles'...