Add alternate multilanguage tags for same pages but on other language.
To get started with Laravel Multilanguage, use Composer command to add the package to your composer.json project's dependencies:
For Frontend and backend
composer require trinityrank/multilanguage
Only for backend we need this package too
composer require epartment/nova-dependency-container
- You need to publish migration from package
php artisan vendor:publish --provider="Trinityrank\Multilanguage\MultilanguageServiceProvider" --tag="multilanguage-migration"
- And then you need to run migration for alltenant(s)
php artisan tenant:artisan "migrate"
- Or only for one speciffic tenant
php artisan tenant:artisan "migrate" --tenant=[--TENANT-ID--]
- Update database field "multilang_language" to default language for your website
UPDATE `articles` SET `multilang_language`='us' WHERE 1;
UPDATE `pages` SET `multilang_language`='us' WHERE 1;
UPDATE `categories` SET `multilang_language`='us' WHERE 1;
UPDATE `static_pages` SET `multilang_language`='us' WHERE 1;
- Add field to your (Operater) resource into "fields" method
use Trinityrank\Multilanguage\MultilanguagePanel;
...
MultilanguagePanel::make()
- Or if you use conditional fields than just add this into "fields" method
// use "$this" or "self::", depends of resource structure
$this->getMultilanguagePanel('Multilanguage', 'multilanguage')
- Fields where category depends on language select
// use "$this" or "self::", depends of resource structure
// $this->getMultilanguageCategory("Language", [Resource::class, Model::class, ['rules']]),
// example:
$this->getMultilanguageCategory("Language", [ReviewPageCategory::class, TypesReviewPageCategory::class, ['required']]),
Add this in tenant-default config
'conditional_fields' => [
...
'{{your_page_type_name}}' => [
'categories' => [
'visible' => true,
'rules' => ['required', 'min:1', 'max:1', ... ]
],
]
...
]
Add this in tenant-{{tenant name}} config
'conditional_fields' => [
...
'{{your_page_type_name}}' => [
'language' => [
'visible' => true
],
'categories' => [
'visible' => true,
'visibility' => ['onlyOnIndex'],
'rules' => ['required', 'min:1', 'max:1']
],
]
...
]
In your "config\app.php" add multilanguage locales (use ISO language codes). For example:
'locales' => [
"us" => "USA",
"uk" => "Great Britain",
"ca" => "Canada",
"au" => "Australia",
"de" => "German",
"at" => "Austria",
],
Add helper function to "composer.json" file
"autoload": {
"files": [
"vendor/trinityrank/multilanguage/src/Frontend/helpers.php"
],
...
}
And then run:
composer dump-autoload
And change default "route()" method to "multilang_route()"
In your "config\app.php" add multilanguage locales (use ISO language codes). For example:
'locales' => ['us', 'uk', 'ca', 'au', 'de', 'at'],
- For hreflang metatags add this to yout
master.blade
file in head tag
<!-- Multilanguage alternate link tags -->
{!! Trinityrank\Multilanguage\Frontend\HreflangDisplay::meta_tags($item) !!}
- At the bottom of
app.php
add this part of code and change values according to the website settings
// Url structure scheme (same as multicore tenant config file)
'services' => [
'deals' => false,
'MoneyPage' => [
'include_category_in_url' => false,
'slug' => 'best',
],
'News' => [
'include_category_in_url' => false,
'slug' => 'news',
],
'Blog' => [
'include_category_in_url' => false,
'slug' => false,
],
'ReviewPage' => [
'include_category_in_url' => false,
'slug' => 'reviews',
]
],