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 shortname
{{Str::upper(sLang::langSwitcher()[evo()->getConfig('lang')]['short'])}}
Implementing a Language Switcher in Blade template
@foreach(sLang::langSwitcher() as $lang)
<a href="{{$lang['link']}}">{{Str::upper($lang['short'])}}</a>
@endforeach
Example returns langSwitcher
^ 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. This is the Main Menu and the 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()
{
$this->data['menu_main'] = sLangContent::langAndTvs(evo()->getConfig('lang', 'uk'))
->whereTv('menu_main', 1)
->where('hidemenu', 0)
->orderBy('menuindex')
->active()
->get();
$this->data['menu_footer'] = sLangContent::langAndTvs(evo()->getConfig('lang', 'uk'))
->whereTv('menu_footer', 1)
->where('hidemenu', 0)
->orderBy('menuindex')
->active()
->get();
}
Output in the Blade template
@if($menu_main)
<ul>
@foreach($menu_main as $menu)
@if($menu->id == evo()->documentObject['id'])
<li class="active">
<a>{{$menu->menutitle}}</a>
</li>
@else
<li>
<a href="@makeUrl($menu->id)">{{$menu->menutitle}}</a>
</li>
@endif
@endforeach
</ul>
@endif
TV variables
The langAndTvs()
method makes it quite easy to get TV parameters associated with a resource. For example, the tv_image parameter.
Get in the controller.
$resource = sLangContent::langAndTvs(evo()->getConfig('lang'), ['tv_image'])->active()->first();
Display in the template.
{{$resource->tv_image}}
The whereTv()
method allows you to use a filter based on the value of the TV parameter if necessary.
$resource = sLangContent::langAndTvs(evo()->getConfig('lang'), ['tv_image'])->whereTv('tv_image', '!=', '')->get();
Resource fields in Admin panel
You can control the display of resource fields on general tabs through an event sLangDocFormFieldRender
.
Usage example from your plugin:
Event::listen('evolution.sLangDocFormFieldRender', function($params) {
if ($params['content']['template'] == 7) {
if ($params['name'] == 'introtext') {
return view('slang.introtext', $params)->render();
}
}
});