- Admin Interface
- How It Works
- The Language Model
- Overwrite Bindings
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:
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.
How it Works
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 Language Model
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
use Varbox\Models\Language; $languages = Language::alphabetically()->get();
You can get only the default language by using the
onlyDefault query scope present on the
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
use Varbox\Models\Language; $languages = Language::excludingDefault()->get();
You can get all active languages by using the
onlyActive query scope present on the
use Varbox\Models\Language; $languages = Language::onlyActive()->get();
You can get all inactive languages by using the
onlyInactive query scope present on the
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.
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:
This class represents the language model.
This class is used for interactions with the "Admin -> Multi Language -> Languages".
This class is used for validating any translation when creating or updating.
The view composer for the language switcher in the header.
This class is used for applying the filtering logic.
This class is used for applying the sorting logic.