Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add more languages #102

Open
taskibayev opened this issue Dec 5, 2015 · 14 comments
Open

Is it possible to add more languages #102

taskibayev opened this issue Dec 5, 2015 · 14 comments

Comments

@taskibayev
Copy link

Hi. Is it possibe to add more languages

@martins-giberts
Copy link

I am using https://github.com/OmgDef/yii2-multilingual-behavior with this CMS and so far it works perfectly.

@taskibayev
Copy link
Author

thanks for answer. but I'll test it later

@alladas
Copy link

alladas commented Aug 2, 2016

Hello @martins-giberts
I wonder how did you override the easyii find method in your models?
public static function find() { return new MultilingualQuery(get_called_class()); }
Asking because not sure how to go, since Easyii is using a unique find() method for all its models.
Thanks for any tips.

@Saraylu
Copy link

Saraylu commented Dec 9, 2016

I am using https://github.com/OmgDef/yii2-multilingual-behavior with this CMS and so far it works perfectly.

Can you describe how to do it?
(Now I get better results, in feature come back and describe my method )

@tixaskiy
Copy link

Согласен с предидущим постом, можно подробности, может есть смысл написать статью по этому поводу?!

@martins-giberts
Copy link

martins-giberts commented May 19, 2017

@alladas @msoa @tixaskiy
I don't know how, but I completely missed this thread. Im so sorry guys. If its still important to anyone, I will try to provide as much info as possible. Please let me know.

I coppy pasted example module and migration from one of products I made with EasyIii, here is how I did it:
ModuleFile
DB migration file for table
ExampleView
UrlManager Class
Routes config

@tixaskiy
Copy link

Тема актуальная, по этому буду рад любой информации. Пример который вы выложили это мультиязычность для SeoText , правильно я вас понял?

@martins-giberts
Copy link

@tixaskiy Yes, exactly. I made this change for Seo Text Model to support multi language. You will need additional changes for CMS Form for inserting new fields, I will check if I can extract simple code samples but it should be straight forward from the Module file what kind of field names you need for input fields.

@tixaskiy
Copy link

Спасибо, буду ждать примеры. Хочется видеть как будет выглядеть админ часть для добавления и как это выводить в виде?. Плюс какой будет путь сайта с тем или иным языком.

@martins-giberts
Copy link

@tixaskiy I added another link for Form View. On public part I am using Route switch that sets cookie with the selected language, and with my own custom code get module field that is for selected language:
$module->{'field_' . $language}

@martins-giberts
Copy link

@tixaskiy Just in case - here are config and UrlManager class I am using to switch between languages:
UrlManager Class
Routes config

Switcher is completely custom, you just need to add language attribute to any route you are generating in views, either existing/selected one or forced one for switching language.

@tixaskiy
Copy link

@martins-giberts Спасибо за помощь, если появятся вопросы на пишу.

@tixaskiy
Copy link

А можно посмотреть как выглядит \app\modules\admin\components\ActiveRecord ?

@martins-giberts
Copy link

@tixaskiy

<?php
namespace app\modules\admin\components;

/**
 * Base active record class for easyii models
 * @package app\modules\admin\components
 */
class ActiveRecord extends \yii\db\ActiveRecord
{
    /** @var string  */
    public static $SLUG_PATTERN = '/^[0-9a-z-]{0,128}$/';

    /**
     * Get active query
     * @return ActiveQuery
     */
    public static function find()
    {
        return new ActiveQuery(get_called_class());
    }

    /**
     * Formats all model errors into a single string
     * @return string
     */
    public function formatErrors()
    {
        $result = '';
        foreach($this->getErrors() as $attribute => $errors) {
            $result .= implode(" ", $errors)." ";
        }
        return $result;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants