Use in Blade
Current language
{{ evo()->getLocale() }}
or
{{ evo()->getConfig('lang') }}
Default language
{{ evo()->getConfig('s_lang_default') }}
List of frontend languages by comma
{{ evo()->getConfig('s_lang_front') }}
Translation of phrases
In Blade:
@lang('phrase')
In Controller:
__('phrase')
Localized versions of your page for Google hreflang
{!! sLang::hreflang() !!}
Language Switcher
Show current language anywhere with name or short name:
{{ Str::upper(sLang::langSwitcher()[evo()->getConfig('lang')]['short']) }}
Implement a language switcher in a Blade template:
@foreach(sLang::langSwitcher() as $lang)
<a href="{{ $lang['link'] }}">{{ Str::upper($lang['short']) }}</a>
@endforeach
Example langSwitcher result:
^ array:2 [▼
"uk" => array:6 [▼
"name" => "Українська"
"short" => "Укр"
"ISO 639-1" => "uk"
"ISO 639-3" => "ukr"
"country" => "Ukraine"
"link" => "https://example.com/"
]
"en" => array:6 [▼
"name" => "English"
"short" => "Eng"
"ISO 639-1" => "en"
"ISO 639-3" => "eng"
"country" => "English"
"link" => "https://example.com/en/"
]
]
Menu list
By default, sLang offers 2 menu areas: Main Menu and Footer Menu. These areas are built on TV menu_main and menu_footer parameters and displayed in the resource settings tab.
Data preparation in BaseController.php:
use Seiger\sLang\Models\sLangContent;
...
public function globalElements()
{
// Tree menu
$this->data['mainMenu'] = sLangContent::withTVs(['tv_image'])
->where('hidemenu', 0)
->whereTv('menu_main', 1)
->orderBy('parent_id')
->orderBy('menuindex')
->active()
->get()
->toTreeParent(0);
// Simple menu
$this->data['mainMenu'] = sLangContent::withTVs(['tv_image'])
->whereTv('menu_main', 1)
->where('hidemenu', 0)
->orderBy('menuindex')
->active()
->get();
$this->data['footerMenu'] = sLangContent::whereTv('menu_footer', 1)
->where('hidemenu', 0)
->orderBy('menuindex')
->active()
->get();
}
Output in the Blade template:
@if($mainMenu)
<ul>
@foreach($mainMenu as $menu)
<li>
@if($menu->id == evo()->documentObject['id'])
<a>{{ $menu->menutitle }}</a>
@else
<a href="{{ $menu->fullLink }}" {!! $menu->linkAttributes !!}>{{ $menu->menutitle }}</a>
@endif
</li>
@endforeach
</ul>
@endif
For unlimited nesting, move the menu item into a recursive partial.
TV variables
The withTVs() scope makes it easy to retrieve TV parameters associated with a resource.
$resource = sLangContent::withTVs(['tv_image'])->active()->first();
Display in the template:
{{ $resource->tv_image }}
The whereTv() method allows filtering by TV parameter value:
$resources = sLangContent::withTVs(['tv_image'])->whereTv('tv_image', '!=', '')->get();
Combine multiple helpers:
$resources = sLangContent::lang('uk')->withTVs(['color', 'price'])->whereParent($parentId)->active()->get();
Deprecated:
langAndTvs()still works for existing code. Uselang()andwithTVs()for new queries.
Resource fields in Admin panel
You can control the display of resource fields on general tabs through the sLangDocFormFieldRender event.
Event::listen('evolution.sLangDocFormFieldRender', function($params) {
if ($params['content']['template'] == 7) {
if ($params['name'] == 'introtext') {
return view('slang.introtext', $params)->render();
}
}
});