Localisation management dependency for Laravel Enso.
click on the photo to view a short demo in compatible browsers
- allows an easier management of languages, keys and translations in the context of a multi language application
- uses the newer Laravel
__()
translation method and stores keys and translations inside a JSON file - permits adding as many languages as you require and the quick creation of translations for the keys you need
- the language selector is easily accessible in the right-hand sidebar
-
the
languages
table stores the available languages for localisationname
- the language code, e.g. 'en'display_name
- the label for the language, visible in the UI, e.g. 'English'flag
- the icon class used for showing the flag
-
when translating, the new Laravel mechanism is used, respectively the
__()
function -
the main language is considered to be english
-
the keys are, by convention, in english and in a human readable format e.g. 'Date of Birth', and if a key is not found, the value of the key is used instead
-
the keys and the values for the keys are kept in
resources/lang/*code*.json
where code is the language code, e.g. 'de' for german, with the exception for the english language, since keys are already in english -
due to Laravel's implementation, there are 4 translation categories which cannot be implemented using the new mechanism:
auth
,pagination
,passwords
,validation
. For this reason, we keep the respective language files in their proper language sub-folders -
the moment a new language is added from the interface
- the new language is saved in the database
- the four php translation files are copied to a newly created language folder
- a new JSON language file is generated, containing the keys for the existing translations. The keys are collected using as reference the first existing JSON file
-
when deleting a language
- the language is removed from the database
- the language folder and its contents are removed
- the JSON language file is removed
-
the
set-language
middleware is used to set the locale for the backend, for each request, depending on the user's language preference -
the
LanguagePolicy
ensures that when deleting a language, a user cannot delete the default language, or the language he has currently set as active in his preferences -
the list of languages and the translations are loaded on app init, so the changes will be available at the next login or at a page refresh
Please note that because we want to keep the compiled size down, throughout the enso ecosistem, icons are imported selectively.
What this means for the localisation package, is that when adding a new language, you should also make sure you import the required flag icon SVG and declare the corresponding class. The proper place to include the new icon is:
resources/assets/sass/app.scss
php artisan vendor:publish --tag=localisation-assets
- the VueJS components and pagesphp artisan vendor:publish --tag=enso-assets
- a common alias for when wanting to update the VueJS assets, once a newer version is released, can be used with the--force
flag
- sync-json command / button
The Laravel Enso Core package comes with this package included.
Depends on:
- Core for middleware, user and preferences models
- Structure manager for the migrations
- Datatable for displaying the list of languages
- FormBuilder for creating the forms when managing languages
- Helpers for utility classes and traits
are welcome. Pull requests are great, but issues are good too.
This package is released under the MIT license.