-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback locale not taken from locale list in translation exists, even if property doesn't. #142
Comments
I patched it by copying getAttributeOrFallback in my model with this structure private function getAttributeOrFallback(?string $locale, string $attribute)
{
$translation = $this->getTranslation($locale);
$fallbackLocale = $this->getFallbackLocale($locale);
if (
(
! $translation instanceof \Illuminate\Database\Eloquent\Model
||
$this->isEmptyTranslatableAttribute($attribute, $translation->$attribute)
)
&& $this->usePropertyFallback()
) {
$translation = $this->getTranslation($fallbackLocale, false);
}
if ($translation instanceof Model && $value = $translation->$attribute) {
return $value;
}
foreach ($this->getLocalesHelper()->all() as $configuredLocale) {
if (
$locale !== $configuredLocale
&& $fallbackLocale !== $configuredLocale
&& ($translation = $this->getTranslationByLocaleKey($configuredLocale))
&& ($value = $translation->$attribute)
) {
return $value;
}
}
return null;
} |
Hey, Right now the whole fallback topic is a total mess. It's a pain for me as the maintainer to, well, maintain but also for the users to understand. It's also pretty hard to configure everything that it works like expected, it's nearly impossible to adjust and most times the performance isn't the best because the code covers a lot more functionality. That's why I've come up with the "strategy" idea (naming isn't final, open for ideas). The basic idea is something like a pipeline of translation finders/strategies/pipes and the first that doesn't return There's also #129 already with the first implementation idea. Because of all this and the fact that I'm not 100% sure if the described case and problem is a real bug or more like a feature request. 🤔 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. Thank you for your contributions. |
Describe the bug
When fallback_locale is set to null, if a translation model is found for the main locale, it will not try the locales is the locales array. This comes into contradiction with https://docs.astrotomic.info/laravel-translatable/package/fallback-locale#app-wide . (It will however go through the array if a translation model for the main locale is not found, which renders the scenario even stranger)
To Reproduce
Set a model's $useTranslationFallback to true.
Set config fallback_locale to null.
Have at least two locales in locales array.
Save instance of model with its translations having null for the property in one locale and some data (a string in my case) in the other. While app is in locale that has null property, try to call the property that has null.
Notice that it wasn't translated from the other locale.
Expected behavior
A clear and concise description of what you expected to happen.
Versions (please complete the following information)
Additional context
The getTranslation() method to get translation model properly calls the array if no other model has been found before
but the getAttributeOrFallback() only calls getFallBackLocale()
which does not check the array (getFallbackLocale())
The text was updated successfully, but these errors were encountered: