public function init($language = null)
    {
        if (!$language) {
            $language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
        }
        if (strlen($language) < 2) {
            return $this->error('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
        }

        $model = $this->param('model');
        if (empty($model)) {
            $model = 'I18nMessages';
        }

        $fields = ['domain', 'singular', 'plural', 'context'];

        $model = TableRegistry::get($model);
        $messages = $model->find()
            ->select($fields)
            ->distinct(['domain', 'singular', 'context'])
            ->enableHydration(false)
            ->toArray();

        $entities = $model->newEntities($messages);

        $return = $model->getConnection()->transactional(
            function () use ($model, $entities, $language) {
                $model->deleteAll([
                    'locale' => $language,
                ]);

                foreach ($entities as $entity) {
                    $entity->set('locale', $language);
                    if ($model->save($entity) === false) {
                        return false;
                    }
                }
            }
        );

        if ($return) {
            $this->out('Created ' . count($messages) . ' messages for "' . $language . '"');
        } else {
            $this->out('Unable to create messages for "' . $language . '"');
        }
    }
public function init($language = null)
    {
        if (!$language) {
            $language = $this->in('Please specify language code, e.g. `en`, `eng`, `en_US` etc.');
        }
        if (strlen($language) < 2) {
            return $this->error('Invalid language code. Valid is `en`, `eng`, `en_US` etc.');
        }

        $model = $this->param('model');
        if (empty($model)) {
            $model = 'I18nMessages';
        }

        $fields = ['domain', 'singular', 'plural', 'context'];

        $model = TableRegistry::get($model);
        $messages = $model->find()
            ->select($fields)
            ->distinct(['domain', 'singular', 'context'])
            ->enableHydration(false)
            ->toArray();

        $entities = $model->newEntities($messages);

        $return = $model->getConnection()->transactional(
            function () use ($model, $entities, $language) {
                $model->deleteAll([
                    'locale' => $language,
                ]);

                foreach ($entities as $entity) {
                    $entity->set('locale', $language);
                    if ($model->save($entity) === false) {
                        return false;
                    }
                }
            }
        );

        if ($return) {
            $this->out('Created ' . count($messages) . ' messages for "' . $language . '"');
        } else {
            $this->out('Unable to create messages for "' . $language . '"');
        }
    }
public function init ( $ language = null ) { if ( ! $ language ) { $ language = $ this -> in ( 'Please specify language code, e.g. `en`, `eng`, `en_US` etc.' ) ; } if ( strlen ( $ language ) < 2 ) { return $ this -> error ( 'Invalid language code. Valid is `en`, `eng`, `en_US` etc.' ) ; } $ model = $ this -> param ( 'model' ) ; if ( empty ( $ model ) ) { $ model = 'I18nMessages' ; } $ fields = [ 'domain' , 'singular' , 'plural' , 'context' ] ; $ model = TableRegistry :: get ( $ model ) ; $ messages = $ model -> find ( ) -> select ( $ fields ) -> distinct ( [ 'domain' , 'singular' , 'context' ] ) -> enableHydration ( false ) -> toArray ( ) ; $ entities = $ model -> newEntities ( $ messages ) ; $ return = $ model -> getConnection ( ) -> transactional ( function ( ) use ( $ model , $ entities , $ language ) { $ model -> deleteAll ( [ 'locale' => $ language , ] ) ; foreach ( $ entities as $ entity ) { $ entity -> set ( 'locale' , $ language ) ; if ( $ model -> save ( $ entity ) === false ) { return false ; } } } ) ; if ( $ return ) { $ this -> out ( 'Created ' . count ( $ messages ) . ' messages for "' . $ language . '"' ) ; } else { $ this -> out ( 'Unable to create messages for "' . $ language . '"' ) ; } }
Initialize a new languages from exiting messages.

Any existing translations for specified language will be deleted.

@param string|null $language Language code to use.

@return int|null
Initialize a new languages from exiting messages .