Get a translation or create new.

@param string $locale

@return \Illuminate\Database\Eloquent\Model
508142
protected function translateOrNew(string $locale): Model
    {
        if (isset($this->translationCache[$locale])) {
            return $this->translationCache[$locale];
        }

        if (!$this->exists) {
            return $this->translations()->newModelInstance(['locale' => $locale]);
        }

        return $this->translations()
            ->where('locale', $locale)
            ->firstOrNew(['locale' => $locale]);
    }
515524
public static function getValidator(string $locale = 'en_US'): Factory {
    $translator       = new Translator($locale, new MessageSelector());
    $validatorFactory = new Factory($translator);

    return $validatorFactory;
  }
791842
public function setLocale($locale = null)
    {
        if (is_null($locale)) {
            $locale = $this->getParent()->getLocale();
        }
        $this->locale = $locale;

        return $this;
    }
1282328
protected function newTranslation($locale = null, array $attributes) {
        $locale = isset($locale) ? $locale : Locale\get_active_locale();

        $language = $this->getByLocale($locale);

        $class = $this->classTranslation();

        $update = [
            'language_id' => $language->id,
             isset($this->translation_id) ? $this->translation_id : str_singular($this->getModel()->getTable()) . '_id' => $this->id,
        ];

        $attributes = array_merge($update, $attributes);

       return $class::updateOrCreate($update, $attributes);
    }
496217
public function setLocale($locale)
    {
        if ($this->isRoot) {
            $this->translator->setLocale($locale);

            return $this;
        }

        $this->locale = $locale;

        return $this;
    }
145124
public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
    {
        if (!isset($this->currentTranslations[$locale])) {
            if (null !== $this->collSmartyFilterI18ns) {
                foreach ($this->collSmartyFilterI18ns as $translation) {
                    if ($translation->getLocale() == $locale) {
                        $this->currentTranslations[$locale] = $translation;

                        return $translation;
                    }
                }
            }
            if ($this->isNew()) {
                $translation = new ChildSmartyFilterI18n();
                $translation->setLocale($locale);
            } else {
                $translation = ChildSmartyFilterI18nQuery::create()
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
                    ->findOneOrCreate($con);
                $this->currentTranslations[$locale] = $translation;
            }
            $this->addSmartyFilterI18n($translation);
        }

        return $this->currentTranslations[$locale];
    }
182272
public function getLocaleChain(Locale $locale)
    {
        $fallbackRule = $this->configuration->getFallbackRule();
        $localeChain = [(string)$locale => $locale];

        if ($fallbackRule['strict'] === true) {
            foreach ($fallbackRule['order'] as $localeIdentifier) {
                $localeChain[$localeIdentifier] = new Locale($localeIdentifier);
            }
        } else {
            $locale = $this->findBestMatchingLocale($locale);
            while ($locale !== null) {
                $localeChain[(string)$locale] = $locale;
                $locale = $this->getParentLocaleOf($locale);
            }
            foreach ($fallbackRule['order'] as $localeIdentifier) {
                $locale = new Locale($localeIdentifier);
                $locale = $this->findBestMatchingLocale($locale);
                while ($locale !== null) {
                    $localeChain[(string)$locale] = $locale;
                    $locale = $this->getParentLocaleOf($locale);
                }
            }
        }
        $locale = $this->configuration->getDefaultLocale();
        $localeChain[(string)$locale] = $locale;

        return $localeChain;
    }
650461
public function locale($locale = null)
    {
        if ($locale) {
            $this->_locale = $locale;
        }
        if ($this->_locale) {
            return $this->_locale;
        }
        if (isset($this->_params['locale'])) {
            return $this->_params['locale'];
        }
    }
1036604
public function locale(string $locale = null, ...$fallbackLocales)
    {
        if ($locale === null) {
            return $this->getLocalTranslator()->getLocale();
        }

        if (!$this->localTranslator || $this->localTranslator->getLocale() !== $locale) {
            $translator = Translator::get($locale);

            if (!empty($fallbackLocales)) {
                $translator->setFallbackLocales($fallbackLocales);

                foreach ($fallbackLocales as $fallbackLocale) {
                    $messages = Translator::get($fallbackLocale)->getMessages();

                    if (isset($messages[$fallbackLocale])) {
                        $translator->setMessages($fallbackLocale, $messages[$fallbackLocale]);
                    }
                }
            }

            $this->setLocalTranslator($translator);
        }

        return $this;
    }
205167
public function getTranslations(Locale $locale)
    {
        $localeID = $locale->getID();
        $translations = isset($this->translations[$localeID]) ? $this->translations[$localeID][1] : null;
        if ($translations === null) {
            $translations = clone $this->getSourceStrings(true);
            $translations->setLanguage($locale->getID());
            $this->setTranslations($locale, $translations);
        }

        return $translations;
    }
1355686
public function getTranslationFile($locale)
    {
        if (isset($this->locales[$locale]) === false) {
            return null;
        }

        return $this->locales[$locale];
    }
64352
public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
    {
        if (!isset($this->currentTranslations[$locale])) {
            if (null !== $this->collDealerI18ns) {
                foreach ($this->collDealerI18ns as $translation) {
                    if ($translation->getLocale() == $locale) {
                        $this->currentTranslations[$locale] = $translation;

                        return $translation;
                    }
                }
            }
            if ($this->isNew()) {
                $translation = new ChildDealerI18n();
                $translation->setLocale($locale);
            } else {
                $translation = ChildDealerI18nQuery::create()
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
                    ->findOneOrCreate($con);
                $this->currentTranslations[$locale] = $translation;
            }
            $this->addDealerI18n($translation);
        }

        return $this->currentTranslations[$locale];
    }
1207297
public function getTitle($locale = null)
    {
        if ($locale && isset($this->title[$locale])) {
            return $this->title[$locale];
        }

        if (isset($this->title['default'])) {
            return $this->title['default'];
        }

        return $this->getOriginalName();
    }
118918
public function translate($locale = null)
    {
        if (!$locale) {
            $locale = \localizer\locale()->id();
        } else {
            $locale = (int)$locale;
        }

        return $this->getTranslation($locale);
    }
32566
public function getTranslation(string $locale): ?string
    {
        if (! isset($this->text[$locale])) {
            $fallback = config('app.fallback_locale');

            return $this->text[$fallback] ?? null;
        }

        return $this->text[$locale];
    }
400003
public function getUnreviewedInitialTranslations(LocaleEntity $locale)
    {
        $rs = $this->app->make(TranslationExporter::class)->getUnreviewedSelectQuery($locale);

        return $this->buildInitialTranslations($locale, $rs);
    }
372444
public function getTranslation($locale = 'en_US', ConnectionInterface $con = null)
    {
        if (!isset($this->currentTranslations[$locale])) {
            if (null !== $this->collDealerContactI18ns) {
                foreach ($this->collDealerContactI18ns as $translation) {
                    if ($translation->getLocale() == $locale) {
                        $this->currentTranslations[$locale] = $translation;

                        return $translation;
                    }
                }
            }
            if ($this->isNew()) {
                $translation = new ChildDealerContactI18n();
                $translation->setLocale($locale);
            } else {
                $translation = ChildDealerContactI18nQuery::create()
                    ->filterByPrimaryKey(array($this->getPrimaryKey(), $locale))
                    ->findOneOrCreate($con);
                $this->currentTranslations[$locale] = $translation;
            }
            $this->addDealerContactI18n($translation);
        }

        return $this->currentTranslations[$locale];
    }