<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
antonioprimera / laravel-js-localization example snippets
// resources/lang/en/example.php
return [
'welcome' => 'Welcome to our application!',
'apples' => '{0} :name has no apples|{1} :name has one apple|[2,10] :name has :count apples|[11,*] :name has too many apples!',
];
use AntonioPrimera\LaravelJsLocalization\Facades\LocaleManager;
// Get all the available locales via: config('app.available_locales', ['en'])
$locales = LocaleManager::availableLocales();
// Get the default locale via: config('app.locale', 'en')
$defaultLocale = LocaleManager::defaultLocale();
// Get the fallback locale via: config('app.fallback_locale', 'en')
$fallbackLocale = LocaleManager::fallbackLocale();
// Get the current locale via: app()->getLocale()
$locale = LocaleManager::currentLocale();
// Get the locale for the authenticated user, fallback to the session locale and then to the default locale
$userLocale = LocaleManager::authenticatedUserLocale();
// Set the locale for the current request and store it in the session
LocaleManager::setLocale('en');
// Store the locale in the session (will not change the current locale)
LocaleManager::setSessionLocale('en');
// Get the locale from the session
$locale = LocaleManager::sessionLocale();
// Check if a locale is available (checks the available locales)
$available = LocaleManager::isValidLocale('en');
return [
/**
* The folder where the language files are stored, relative to the project root
*
* By default, the language files are stored in the 'lang' folder in the project root.
*/
'language-folder' => 'lang',
/**
* The class that sets the locale in the app
*
* This class must implement AntonioPrimera\LaravelJsLocalization\Interfaces\LocaleSetter.
* By default, the UserSessionLocaleSetter is used, which tries to determine the locale from the authenticated user,
* if a user is logged in, then falls back to the session locale, and finally to the default app locale.
* Replace this with your own class if you have a different way of determining the locale.
*/
'locale-setter' => \AntonioPrimera\LaravelJsLocalization\LocaleSetters\UserSessionLocaleSetter::class,
/**
* The property of the authenticated user model that holds the locale
*
* If you have a property in your user model, that holds the locale of the user, you can set it here,
* and the locale will be set to the value of this property when the user is authenticated.
* You can leave it commented out if you don't have such a property on your user model.
*/
'user-locale-property' => 'language',
];
bash
php artisan js-localization:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.