Laravel Version: last
Voyager Version: last
PHP Version: 7
Database Driver & Version: mysql last
I am using {{$product->getTranslatedAttribute('short_title')}} on view. But I don't want to use it that way.
I want to use it this way : {{$product->title}}. And I want it to show the translation of which language is selected.
I see that there is a library that can do this.
https://github.com/spatie/laravel-translatabl
Is there a way to do this or am I doing something wrong?
Voyager doesn't have a way to do that, and I'm not planning to add it.
We are, however, working on v2.0 which will be a sizable rewrite of much of the core functionality. One of the things I want to change is how translations work, so we'll consider that request for then
I am complated my project and there are a lot normal variable {{$x->title}}
Now I need to change all variable to getTranslatedAttribute.
Well, How about custom blade directive? Can I use custom blade directive? Is this good idea?
Like this:
\Blade::directive('votrans', function ($expression) {
return $expression;
});
best regards.
It's your project, so you're free to do whatever you'd like. Yes a blade directive would work.
However, if you weren't using Voyager, how would you expect it to just work? Even in just basic laravel you'd have to change it all to __(....)
You right, but another libraries they did as I wanted.
Yes, but that's a massive rewrite and not something we're able/willing to do before 2.0
Are you looking for this?
https://docs.laravelvoyager.com/core-concepts/multilanguage#translate-the-whole-model
Yes, but it's not working with getThumbnail() method.
Say: Call to undefined method TCG\Voyager\Translator::getThumbnail()
Instead of overriding the variable (like $post = $post->translate(...)) just make it a second var, e.g. $translated_post
Nonetheless we provide a way to translate the whole model. Closing
Now I want to making only sensible accessors. I can't use different variable and edit anything variable. Because there are approximately 500 variable. Nonetheless searching another way. If I found then report with branch. I think a lot of people like to use something like this.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.