Using scopes to get models for different languages
Internationalizing your application is not an easy task. You need to translate interfaces, translate messages, format dates properly, and so on. Yii helps you to do this by giving you access to the Common Locale Data Repository (CLDR) data of Unicode and providing translation and formatting tools. When it comes to applications with data in multiple languages, you have to find your own way.
From this recipe, you will learn a possible way to get a handy model function that will help to get blog posts for different languages.
Getting ready
Create a new application by using
yiic webappas described in the official guide at the following URL:http://www.yiiframework.com/doc/guide/en/quickstart.first-app
Set up the database connection and create a table named
postas follows:DROP TABLE IF EXISTS `post`; CREATE TABLE IF NOT EXISTS `post` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `lang` VARCHAR(5) NOT NULL DEFAULT 'en', `title` VARCHAR...