The Varbox platform also puts at your disposal the Admin -> Multi Language -> Languages section from where you can manage the languages for your application.
As a bonus, 135 languages are already seeded for you when installing the platform.
In order to provide you with a complex crud functionality inside the admin, the languages crud implements the following out of the box:
<style> #available-filter-operators-list > p { column-count: 3; -moz-column-count: 3; -webkit-column-count: 3; column-gap: 2em; -moz-column-gap: 2em; -webkit-column-gap: 2em; } #available-filter-operators-list a { display: block; color: #4AAEE3; } </style>Before going deeper, you should know that there's already a section in the admin from where you can manage all your translations and languages.
You can find the languages section inside Admin -> Multi Language -> Languages.
Feel free to explore all available options this section offers.
First of all, let's understand the architecture behind languages and their workflow.
Even though you have 135 languages, the chances you're going to be using all of them are very slim.
Because of that, only active languages will show in the language switcher from the header.
You can apply the same logic in your frontend to use the multi language functionality only for the languages your application supports.
Beside active languages support, we also offer the ability to set a default language from the admin, which by default is set to English. You can use this default language to fallback to it in your edge cases.
It can only be a single default language, so saving another language as default, will cause the old one to loose its default status.
The Varbox\Models\Language
model is used to manage your languages.
You can get all languages sorted in alphabetical order by using the alphabetically
query scope present on the Translation
model.
use Varbox\Models\Language;
$languages = Language::alphabetically()->get();
You can get only the default language by using the onlyDefault
query scope present on the Translation
model.
use Varbox\Models\Language;
$language = Language::onlydefault()->first();
You can get all languages except the default on by using the excludingDefault
query scope present on the Translation
model.
use Varbox\Models\Language;
$languages = Language::excludingDefault()->get();
You can get all active languages by using the onlyActive
query scope present on the Translation
model.
use Varbox\Models\Language;
$languages = Language::onlyActive()->get();
You can get all inactive languages by using the onlyInactive
query scope present on the Translation
model.
use Varbox\Models\Language;
$languages = Language::onlyInactive()->get();
In your projects, you may stumble upon the need to modify the behavior of these classes, in order to fit your needs.
Varbox makes this possible via the config/varbox/bindings.php
configuration file. In that file, you'll find every customizable class the platform uses.
<style> p.overwrite-class { display: block; font-family: SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace; font-weight: 600; font-size: 15px; margin: 0; } </style>For more information on how the class binding works, please refer to the Custom Bindings documentation section.
The language classes available for binding overwrites are:
Varbox\Models\Language
Found in config/varbox/bindings.php
at models.language_model
key.
This class represents the language model.
Varbox\Controllers\LanguagesController
Found in config/varbox/bindings.php
at controllers.languages_controller
key.
This class is used for interactions with the "Admin -> Multi Language -> Languages".
Varbox\Requests\LanguageRequest
Found in config/varbox/bindings.php
at form_requests.language_form_request
key.
This class is used for validating any translation when creating or updating.
Varbox\Composers\LanguagesComposer
Found in config/varbox/bindings.php
at view_composers.languages_view_composer
key.
The view composer for the language switcher in the header.
Varbox\Filters\LanguageFilter
Found in config/varbox/bindings.php
at filters.language_filter
key.
This class is used for applying the filtering logic.
Varbox\Sorts\LanguageSort
Found in config/varbox/bindings.php
at sorts.language_sort
key.
This class is used for applying the sorting logic.