GrafiteInc / CMS

Decoupled CMS for any Laravel app, gain control of: pages, blogs, galleries, events, images, custom modules and more.
https://cms.grafite.ca
MIT License
495 stars 104 forks source link

Multilanguage does not work on menu links #187

Closed RushabhJoshi closed 5 years ago

RushabhJoshi commented 5 years ago

Describe the bug I have created one menu name Main(slug: main) In the menu, I have one link named about (fr translation "sur")

when I switch the language from English to French page content get translated but not menu link

To Reproduce Steps to reproduce the behavior:

  1. Go to 'menus'
  2. Click on 'Add New'
  3. Create a menu with name= Main and slug= main
  4. Click on 'Add Link'
  5. Create a link with name= About
  6. Click on French tab in link edit page
  7. Update menu name= Sur
  8. Click on 'back to site'
  9. Change language to French

Expected behavior It should show link title 'Sur' but it is still showing me 'About'

Screenshots https://screenshots.firefox.com/BhsL7a60fxzwdjuv/blog.laravel.local

Desktop (please complete the following information):

Additional context It does translate page content but not menu link

mlantz commented 5 years ago

There is a minor issue if you're using custom templates for the menu, if you use the @menu('main') without a custom view then it works fine, but the links were not translated if you used the custom view. I've corrected that and will be pushing a solution shortly.

RushabhJoshi commented 5 years ago

https://screenshots.firefox.com/TDXAR463tXy8WEjs/blog.laravel.local

I have removed the custom template and used @menu('main') not it is not showing menu either see the screen shot now about menu item is missing it is not even in page source

RushabhJoshi commented 5 years ago

I don't know how you going to do this but there is a little correction in TranslationRepository

this is my code snippet

`public function findByEntityId($entityId, $entityType)
{
    $item = $this->model->where('entity_type', $entityType)->where('entity_id', $entityId)->first();

    if ($item && $entityType == 'Grafite\Cms\Models\Link') {
        return $item->data;
    }

    if ($item && ($item->data->is_published == 1 || $item->data->is_published == 'on') && $item->data->published_at <= Carbon::now(config('app.timezone'))->format('Y-m-d H:i:s')) {
        return $item->data;
    }

    return null;
}`

Though there is no published_at or is_published field in links we need to by pass this check

ddjikic commented 5 years ago

@RushabhJoshi change the template to use <li class="nav-item"><a class="nav-link" href="{{ url(''.$link->page->translation(config('app.locale'))->data->url) }}">{{ $link->translation(config('app.locale'))->data->name }}</a></li>