-
Notifications
You must be signed in to change notification settings - Fork 320
Fallback to default if translation is missing #23
Comments
Yes, please read the readme file for the basic instructions. The default locale is set like this. |
ok, i don't think i made my self clear. Say you have EN as default and FR as a secondary. Field title in EN is there but title in FR is not in the DB cause the user has not translated it yet. Naturaly, a translate('fr')->title returns NULL. |
Oh, sorry. Now I see what you mean. Well, this feature is not available at the moment. I am leaving the issue open until a solution is found. |
If i might suggest 2 approaches.
What do you think? On Tue, Jun 10, 2014 at 10:19 AM, Dimitrios Savvopoulos <
|
// Default locale is 'en'
echo $country->getTranslation('cn', true)->name // 'Greece'
// Alias of the above
echo $country->translateOrDefault('cn')->name // 'Greece' Is something like that ok for you? |
that looks great |
I deleted my previous comment as I didn't reed dimsav's comment correctly. It seems to be a good enhancement. |
Feature is now implemented in version 4.1 |
I'm having trouble trying to understand the new
Something like this is working for me public function getTranslation($locale = null, $withFallback = false)
{
$locale = $locale ?: App::getLocale();
if ($this->getTranslationByLocaleKey($locale))
{
$translation = $this->getTranslationByLocaleKey($locale);
}
elseif ($withFallback && $this->getTranslationByLocaleKey(\Config::get('app.fallback_locale')))
{
$translation = $this->getTranslationByLocaleKey(\Config::get('app.fallback_locale'));
}
else
{
$translation = $this->getNewTranslationInstance($locale);
$this->translations->add($translation);
}
return $translation;
} Please tell me if I'm missing something :) Thank you! |
Hi @gpasci, I understand your confusion. However, could you please explain where you would use this behaviour? |
Hi, sorry for the delay. I'm setting
Then, thanks to your work, fetching the localized content is flawless, until a fallback value is needed. Clearly according to tests your class seems to work as expected (I must say I've not run them) so the problem is in the outer environment. My guess, also noticing that you aren't using I can send you the code if you want to take a look at how I'm implementing it. Sorry if my english is not helping.. Thank you again! |
Hi @gpasci, I wasn't aware of I agree with you that this should be used as fallback_locale and not the I created issue #24 to fix this in a future version. |
Is there a way to do that? It is very common for translations to be missing in some languages, in which case we should fall back to the default one.
The text was updated successfully, but these errors were encountered: