04.30
php
saved
franiglesias
Note
First, you need to set a
Configure::write('Config.languages', array('la1', 'la2'));
to indicate what languages your application supports.
Add 'Translate' and 'Multilingual' to the array of Behaviors of your model.
When you want to get multilingual versions of the data, previously you must call
model->getLocales();
to activate the multilingual find.
The translated results comes as an array
[field][la1]
[field][la2]
First, you need to set a
Configure::write('Config.languages', array('la1', 'la2'));
to indicate what languages your application supports.
Add 'Translate' and 'Multilingual' to the array of Behaviors of your model.
When you want to get multilingual versions of the data, previously you must call
model->getLocales();
to activate the multilingual find.
The translated results comes as an array
[field][la1]
[field][la2]
- <?php
- /**
- * Combine multiple languages in returned result sets
- *
- * @package default
- * @author Fran Iglesias
- **/
- class MultilingualBehavior extends ModelBehavior {
- 'configSupportedLocales' => 'Config.languages',
- 'returnLocales' => false,
- );
- $this->_settings = am($this->_settings, $settings);
- $model->multilingual = $this->_settings['returnLocales'];
- }
- }
- function getLocales (&$model, $locales = '*') {
- $model->multilingual = false;
- return;
- }
- if ($locales == '*') {
- $model->multilingual = Configure::read($this->_settings['configSupportedLocales']);
- return;
- }
- }
- $model->multilingual = $locales;
- }
- function afterFind (&$model, $results, $primary) {
- return $results;
- }
- return $results;
- }
- if ($model->multilingual) {
- foreach ($results as $key => $result) {
- $id = $result[$model->name]['id'];
- $query = "SELECT locale, field, content FROM i18n WHERE model='{$model->name}' AND foreign_key = {$id}";
- $datos = $model->query($query);
- foreach ($datos as $i18) {
- // Locale not asked for
- continue;
- }
- // Field not present in original query (2008-03-25)
- continue;
- }
- }
- $results[$key][$model->name][$field][$locale] = $content;
- }
- }
- return $results;
- }
- }
- } // END class MultilingualBehavior extends ModelBehavior
- ?>
Parsed in 0.091 seconds, using GeSHi 1.0.7.14