thyseus / yii-user-management

a user management module collection for the yii framework
185 stars 122 forks source link

Translation #61

Closed triptec closed 11 years ago

triptec commented 11 years ago

From the docs

  1. Locale and Language ¶ Locale is a set of parameters that defines the user's language, country and any special variant preferences that the user wants to see in their user interface. It is usually identified by an ID consisting of a language ID and a region ID. For example, the ID en_US stands for the locale of English and United States. For consistency, all locale IDs in Yii are canonicalized to the format of LanguageID or LanguageID_RegionID in lower case (e.g. en, en_us).

So the update function in YumTranslationController should look something like this: The change is "$lang = explode('', $key);"=>"$lang = explode('', $key,2);"

public function actionUpdate($category = null, $message = null, $language = null)
{
    $models = array();
        foreach(Yum::getAvailableLanguages() as $language) {
            $models[] = $this->loadTranslationModel($category, $message, $language);
        }

    if(isset($_POST['YumTranslation']))
    {
        $category = $_POST['YumTranslation']['category'];
        $message = $_POST['YumTranslation']['message'];

        foreach($_POST as $key => $translation) {
            if(substr($key, 0, 11) == 'translation') {
                                    $lang = explode('_', $key,2);
                if(isset($lang[1])) {
                    $lang = $lang[1];
                    foreach(Yum::getAvailableLanguages() as $language) {
                        if($language == $lang) {
                            $model = YumTranslation::model()->find(
                                    'category = :category and message = :message and language = :language ', array(
                                        ':category' => $category,
                                        ':message' => $message,
                                        ':language' => $lang));
                            if(!$model)
                                $model = new YumTranslation();

                            if($translation != '') {
                                $model->message = $message;
                                $model->category = $category;
                                $model->translation = $translation;
                                $model->language = $lang;   
                                $model->save();
                            }
                        }
                    }
                }
            }
        }
        Yum::setFlash('Translations have been saved');
        $this->redirect(array('admin'));
    }

    $this->render('update',array(
                'models'=>$models,
                ));
}
thyseus commented 11 years ago

Good idea! Added it.