OmgDef/yii2-multilingual-behavior

Inherit labels

CyanoFresh opened this issue · 4 comments

Hello! Thanks for the extension! Please add labels inheritance. Example:
name = Name
body = Description
name_ru = Name
body_ru = Description
or inherited labels will be configured in the behavior config.

@CyanoFresh Hi! I often do similar to this

public function attributeLabels()
{
    $labels = [];
    foreach (MultilingualHelper::getLanguageSuffixes() as $lang => $suffix) {
        $labels = array_merge($labels, [
            'text' . $suffix => "Text" . ' (' . $lang . ')',
            'title' . $suffix => "Title" . ' (' . $lang . ')',
            'meta_title' . $suffix => 'Meta Title (' . $lang . ')',
            'meta_description' . $suffix => 'Meta Description (' . $lang . ')',
            'meta_keywords' . $suffix => 'Meta Keywords (' . $lang . ')',
        ]);
    }
    return $labels;
}

What the MultilingualHelper? Please show it class

@CyanoFresh

    /**
     * Returns a suffix array for languages
     * @param bool $excludeDefault
     * @return array
     */
    public static function getLanguageSuffixes($excludeDefault = true)
    {
        $data = [];
        foreach (Yii::$app->params['translatedLanguages'] as $k => $v) {
            $data[$v] = $excludeDefault && $k == Yii::$app->params['defaultLanguage'] ? null : '_' . $k;
        }

        return $data;
    }

In params.php

    'translatedLanguages' => [
        'ru' => 'Русский',
        'en' => 'English'
    ],
    'defaultLanguage' => 'ru',

Thanks! It works.