-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add multilingual #561
Add multilingual #561
Conversation
[ci skip] [skip ci]
Apply fixes from StyleCI
[ci skip] [skip ci]
UPDATE: Added new ways to eager load translations. |
Apply fixes from StyleCI
[ci skip] [skip ci]
Apply fixes from StyleCI
UPDATE: You can now translate a Eloquent Collection like this.
You can also make modifications to the translated models and save them as translations like this.
|
[ci skip] [skip ci]
Apply fixes from StyleCI
[ci skip] [skip ci]
Apply fixes from StyleCI
UPDATE: You can now use the Voyager facade to check if a object or classname is translatable.
|
Hi @Steve-sy, have you setup the config |
Hello there, |
@coppee We use the database for the BREAD translations but will use PHP files for the views-translations. |
Hi @marktopper , thanks for your reply. Sorry, I was not clear enough in my question. I was talking about the other translation eloquent solution (use json in fields) proposed by @akazorg like : https://github.com/spatie/laravel-translatable |
Hi @coppee Voyager is using the extra table approach, not the JSON one. |
Hello, I am new not Voyager, not understood how to translate to pt_br. |
Hi @vitorbrussi, check this #1364. |
It would be very interesting if there was the possibility of having a auto-translator when a locale is defined, and return the translated data In fields that have translation |
That's a nice idea @vitormicillo, we should work on that. |
I created a not very elegant method but it works to auto translate the specific words
|
This method recycles the use of the '\TCG\Voyager\Translator\Collection' $language = $request->header('locale'); |
Really great work on this multilingual feature! I'm trying to think of a way to use it to store my Laravel translations (like in https://github.com/Waavi/translation but I'd like to avoid using a different package/ UI) So basically I'm with my translation files that look something like this
And I'm thinking of adding a class VoyagerTranslator extends Illuminate\Translation\Translator
{
private $labels = null;
public function get($key, array $replace = [], $locale = null, $fallback = true)
{
$lang = $this->getLabel($key);
if ($lang && ($line = $lang->getTranslatedAttribute('label', $locale, false))) {
return $this->makeReplacements($line, $replace);
} else {
return parent::get($key, $replace, $locale, $fallback);
}
}
protected function getLabel($key)
{
if ($this->labels == null) {
$this->labels = \App\Label::with('translations')->get();
}
return $this->labels->where('key', $key)->first();
}
} Any thoughts? Thanks! EDIT: Ok after some edits this seems to work well: this will use Voyager's translation from DB if present otherwise fall back to Laravel language files (once registered with the proper service provider of course). |
I created a method to use the translations
and to use: Ex. $language = $request->header('locale'); works fine for me to use in translating api, I hope it helps many |
Please include this guide in Documentation. It is hard to find it. Thank you. |
Hi! How can I hide the not translated posts? |
Hi, any video tutorial for how to do this like in the gif's images? how to translate the post's content , thanks in advance. |
I tried to implement this, but no luck.
Please update your documentation |
It seems that I can't translate the entire model and other loaded models using Eloquent relationships using the above methods. Any chance of support on this? |
Certainly. But you have to give more informations. |
Hiu @marktopper, you mentioned about a year ago that you wanted to make the translation library in voyager configurable: "About the extra table, I just wanted to let it be flexible. However I can make it extendable so that people can easily make it into JSON instead and remove the translations table." Is the current implementation configurable? Could you point me to how you would replace the current translation implementation with for instance the one from Spatie: spatie/laravel-translatable Thanks! |
@marktopper Any ideas how to fix #3089 ? |
@AlexanderWM, this PR has been merged. 3089 would be a much better place to ask that question |
Progress:
translations
migrationTranslatable
traitTurn this into a plugin for Voyager(Cancelled)Setup:
In order to use this multilingual, you must set some extra languages in the configuration. It will not work where there are only the default language.
Then you must ensure that the models you wish to use the multilingual support for have the
TCG\Voyager\Translatable
trait.Along with that you must define the translatable attributes in the model as so
Usage:
Eager load translations
Get default language value
Get translated value
Translate the whole model
Check if model is translatable
Save changes
Feedback, questions and pull requests are more than welcome.