1. Go to this page and download the library: Download webx-ui/localization library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webx-ui / localization example snippets
use WebxUi\Localization\Locales;
$locales = app(Locales::class);
$locales->codes(); // ['uk', 'ru']
$locales->defaultCode(); // 'uk'
$locales->current(); // the language this request is being answered in
$locales->use('ru'); // false if the site does not publish in it
use WebxUi\Localization\HasTranslations;
class Page extends Model
{
use HasTranslations;
public function translatable(): array
{
return ['title', 'slug', 'content'];
}
}
$page->title; // this request's language, then the fallbacks
$page->title = 'Contacts'; // writes that language, leaves the others alone
$page->forLocale('uk')->title;
$page->getTranslations('title'); // ['en' => 'Contacts', 'uk' => 'Контакти']
$page->setTranslations('title', [...]); // what a form editing every language posts
Page::whereTranslation('slug', $slug, 'uk')->first();
Page::orderByTranslation('title', 'asc')->get();