spatie / laravel-translatable

Making Eloquent models translatable

Home Page:https://spatie.be/docs/laravel-translatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Disable fallback location in config

ehsanrasta opened this issue · comments

If in config file set fallback locale to null then package will use application fallback locale and there is no way to disable this option globally.
I knew that I can pass false to getTranslation method but it would be nice to disable this option in config instead of repeating false everywhere.

commented

for now, extend the trait and override the getTranslation

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

Please consider reopening this issue. This config would be very helpful. Thank you.

For those who want to extend the HasTranslations trait, here is my way:

<?php

namespace App\Models;

use Spatie\Translatable\HasTranslations as TranslatableHasTranslations;

trait HasTranslations
{
    use TranslatableHasTranslations {
        TranslatableHasTranslations::getTranslation as parentGetTranslation;
        TranslatableHasTranslations::translate as parentTranslate;
    }

    public function getTranslation(string $key, string $locale, bool $useFallbackLocale = false)
    {
        return $this->parentGetTranslation($key, $locale, $useFallbackLocale);
    }

    public function translate(string $key, string $locale = '', bool $useFallbackLocale = false): string
    {
        return $this->parentTranslate($key, $locale, $useFallbackLocale);
    }
}