Returns translation entity object for needed language.

@param null|string $language By default uses application current language.

@return \yii\db\ActiveRecord|BaseActiveRecord
488760
public function getTranslation($language = null)
    {
        $language = $language ?: Yii::$app->language;
        $translations = $this->getModelTranslations();

        // search translation by language in exists translations
        foreach ($translations as $translation) {
            // if translation exists - return it
            if ($translation->getAttribute($this->translationLanguageAttrName) === $language) {
                $this->translationsBuffer[] = $translation;

                return $translation;
            }
        }

        // if translation doesn't exist - create and return
        $translationEntityClass = $this->owner->getRelation($this->translationRelationName)->modelClass;

        /* @var BaseActiveRecord $translation */
        $translation = new $translationEntityClass();
        $translation->setAttribute($this->translationLanguageAttrName, $language);
        $translations[] = $translation;
        $this->translationsBuffer = $translations;
        $this->owner->populateRelation($this->translationRelationName, $translations);

        return $translation;
    }
165737
public function langset($lang = null)
    {
        if (!is_null($lang)) {
            $this->langset = $lang;
            return $this;
        } else {
            return $this->langset ?: '';
        }
    }
1156332
public function getKeyword($language = null)
    {
        if (empty($language)) {
            $language = $this->mainLanguageCode;
        }

        if (!is_array($this->keywords) || !array_key_exists($language, $this->keywords)) {
            return null;
        }

        return $this->keywords[$language];
    }
611308
public function getTranslation($lang)
    {
        // Check if locale given
        if (strpos($lang, '_')) {
            $parts = explode('_', $lang);
            $lang = array_shift($parts);
        }

        foreach ($this->getTranslations() as $translation) {
            if ($translation->getLang() === $lang) {
                return $translation;
            }
        }

        $translation = new EmailTranslation($lang);
        $translation->setEmail($this);

        return $translation;
    }
480813
public function url($lang = null)
    {
        if ($this->url === null) {
            if (!$this->id()) {
                return null;
            }

            $this->url = $this->generateUri();
        }

        if ($lang && $this->url instanceof Translation) {
            return $this->url[$lang];
        }

        return strval($this->url);
    }
1360403
public function getMenuByGroup($language = null)
    {
        if( is_null($language) )
            $language = app()->getLocale();

        $this->menuClass::$customAppends = ['item_url', 'item_label'];
        $this->pagesClass::$customAppends = ['page_url'];

        $items = $this->menuGroupsClass::select('id', 'name', 'sequence')
            ->with(['menu' => function ($query) use ($language) {
                $query->with([
                    'children',
                    'page' => function ($query) {
                        $query->with('translations');
                    },
                ])->where('language_code', $language)
                    ->orderBy('sequence');
            }])
            ->where('language_code', $language)
            ->orderBy('sequence', 'ASC')
            ->get();

        foreach ( $items as $key => $item ) {
            $items[$key]['menu'] = $this->formatMenuItems($item->menu);
        }

        return $items;
    }
195216
public function getCustomDate($language, $fallbackLanguage = null)
    {
        $date = $this->getMappedField('date', $language, $fallbackLanguage);

        return $date;
    }
244883
public function getTranslation($lang, $create = false)
    {
        foreach ($this->translations as $translation) {
            if ($lang == $translation->getLang()) {
                return $translation;
            }
        }

        if ($create) {
            $class = $this->getTranslationClass();

            /** @var TranslationInterface $translation */
            $translation = new $class();
            $translation->setLang($lang);
            $this->addTranslation($translation);

            return $translation;
        }

        return null;
    }
147434
public function getLanguage($language)
    {
        if (!$this->getLanguages()->has($language)) {
            $this->getLanguages()->set($language, new LanguageBag());
        }

        return $this->getLanguages()->get($language);
    }
1280483
public function generateElements($language = null)
    {
        $transformer = $this->transformer;

        $sitemapElement = $this
            ->sitemapElementFactory
            ->create(
                $transformer->getLoc($this->route, $language),
                null,
                $this->changeFrequency,
                $this->priority
            );

        return [$sitemapElement];
    }
978960
protected function getTranslator()
    {
        if ( null === $this->_translator )
        {
            $this->_translator = $this->getServiceLocator()
                                      ->get( 'Zend\I18n\Translator\Translator' );
        }

        return $this->_translator;
    }
733241
public function joinLang($language = null)
    {
        if (!$language) {
            if (Yii::$app->id === 'app-backend') {
                $language = Yii::$app->wavecms->editedLanguage;
            } else {
                $language = Yii::$app->language;
            }
        }

        return $this->leftJoin(NewsLang::tableName(),
            NewsLang::tableName() . '.news_id = ' . News::tableName() . '.id AND 
                ' . NewsLang::tableName() . '.language = "' . $language . '"');
    }
1125565
public function getLabel($lang = null)
    {
        $lang = empty($lang) ? $this->getDefaultLanguage() : $lang;

        if (!isset($this->labels[$lang])) {
            return $this->getFirstLabel();
        }

        return $this->labels[$lang];
    }
741149
private function loadTranslation($language)
    {
        $class = $this->translationClass;
        if (!$class) {
            throw new InvalidParamException('Translation class not set.');
        }
        $translation = new $class;
        $translation->{$this->languageAttribute} = $language;

        return $translation;
    }
143224
protected function getTranslated($attribut, $language = null) {
        $language = $language ? $language : Locale::getPrimaryLanguage(Locale::getDefault());
        return $this->getTranslationByLang($language) ? $this->getTranslationByLang($language)->{"get" . $attribut}() : false;
    }
1138836
public function setLanguage($language)
    {
        if ($this->getStorageMethod() == 'cookie') {
            return cookie()->forever($this->getLanguageKey(), $language);
        }
        if ( interface_exists( \Illuminate\Contracts\Session\Session::class ) && method_exists(\Illuminate\Contracts\Session\Session::class, 'put') ) {
            Session::put($this->getLanguageKey(), $language);
        } else {
            Session::set($this->getLanguageKey(), $language);
        }
        $this->registerLanguage();
        return cookie('dummy-cookie', FALSE, 1); //just for cleaner code in the controller
    }
888401
public function createTranslator()
    {
        return $this
            ->entityTranslatorFactory
            ->create(
                $this->entityTranslationProvider,
                $this->configuration,
                $this->fallback
            );
    }