Inherit labels
CyanoFresh opened this issue · 4 comments
CyanoFresh commented
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.
OmgDef commented
@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;
}
CyanoFresh commented
What the MultilingualHelper
? Please show it class
OmgDef commented
/**
* 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',
CyanoFresh commented
Thanks! It works.