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
494 stars 104 forks source link

Request: Translation for Menu Links #109

Closed Nowi5 closed 6 years ago

Nowi5 commented 6 years ago

Hi all,

with Quarx I can translate all my pages and blog entries, which can have different links. But I can't translate menu or more specific the link name. Creating multiple Menus per Language does not make sense in my context. How can I have one menu with multiple translations per link?

Thank you.

Nowi5 commented 6 years ago

Update on LinkRepository

  1. Add

    protected $translationRepo;
    
    public function __construct()
    {
        $this->translationRepo = app(TranslationRepository::class);
    }
  2. Change update

    public function update($links, $input)
    {
        $input['external'] = isset($input['external']) ? $input['external'] : 0;
    
        if (!empty($input['lang']) && $input['lang'] !== config('quarx.default-language', 'en')) {
            return $this->translationRepo->createOrUpdate($links->id, 'Yab\Quarx\Models\Link', $input['lang'], $input);
        } else {
            unset($input['lang']);
            return $links->update($input);
        }
    }
  3. Add use Translatable; to Link Model

  4. Change edit.blade.php

    @if (! is_null(request('lang')) && request('lang') !== config('quarx.default-language', 'en'))
                {!! FormMaker::fromObject($links->translationData(request('lang')), Config::get('quarx.forms.link')) !!}
            @else
                {!! FormMaker::fromObject($links, Config::get('quarx.forms.link')) !!}
            @endif
  5. Change main-menu.blade.php to something like that:

    @if ((config('app.locale') !== config('quarx.default-language')))
        @if ($link->translation(config('app.locale')) !== null)
            @if ($link->external)
                <li><a href="{{ url($link->translation(config('app.locale'))->data->external_url) }}">{{ $link->translation(config('app.locale'))->data->name }}</a></li>
            @else
                <li><a href="{{ url(Config::get('app.locale_prefix').'/'.\Yab\Quarx\Models\Page::find($link->page_id)->url) }}">{{ $link->translation(config('app.locale'))->data->name }}
                </a></li>
            @endif
        @endif
    @else
        @if ($link->external)
            <li><a href="{{ url($link->external_url) }}">{{ $link->name }}</a></li>
        @else
            <li><a href="{{ url(Config::get('app.locale_prefix').'/'.\Yab\Quarx\Models\Page::find($link->page_id)->url) }}">{{ $link->name }}
            </a></li>
        @endif
    @endif
mlantz commented 6 years ago

Based on general feedback I'm doing a full review and refactoring of translations and will be including menus in this process. #132