jeudi 30 novembre 2017

laravel-localization with translated slug stored in database

I try to make a multilingual laravel. To do this, I use different packages

My slugs are translated and stored in database as follows:

{
   "fr": "Accueil",
   "en":"Home"
 }

And all my other translatable data are also like that. And to access one of my data, I use for example, $page->slug or $page->title.

My translations work well. But now, I'm trying to build a menu of languages with the right URLs.

I want, if I am on the page "about" have two links in the menu :

  • http://myapp/en/about
  • http://myapp/fr/a-propos

Here is my code :

<ul>
    @foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
        <li>
            <a rel="alternate" hreflang="" href="">
                
            </a>
        </li>
    @endforeach
</ul>

Unfortunately my urls are bad. If I am on the page "about" in English I have in my menu :

  • http://myapp/en/about
  • http://myapp/fr/about

And I would like http://myapp/fr/a-propos. The data is stored in my database.

Is there a way to make sure to collect data from other languages while in a different locale (here I am in EN and I would like to have the slug FR).

Can you help me ? Thank you very much !



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire