PHP code example of alexjoffroy / laravel-localization
1. Go to this page and download the library: Download alexjoffroy/laravel-localization library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alexjoffroy / laravel-localization example snippets
$l10n = app('localization');
// or
$l10n = L10n::getFacadeRoot();
// or
$l10n = l10n();
// Given `en` is the current locale
$l10n->getLocale(); // `en`
$l10n->setLocale('fr'); // Set the current locale to `fr`
// Given `en` is the current locale
$l10n->isCurrentLocale('en'); // true
$l10n->isCurrentLocale('not-current'); // false
$l10n->isSupportedLocale('en'); // true
$l10n->isSupportedLocale('not-supported'); // false
// Given `en` is the default locale
$l10n->isDefaultLocale('en'); // true
$l10n->isDefaultLocale('not-default'); // false
$l10n->getSupportedLocales(); // All supported locales (from supported_locales)
$l10n->getSupportedLocale('en'); // Given supported locale (from supported_locales)
$l10n->getSupportedLocaleKeys(); // All supported locale keys (from supported_locales)
$l10n->getDefaultLocale(); // Default locale (from default_locale)
// Given `en` is the default locale
$l10n->shouldHideLocaleInUrl('en'); // True if `hide_default_locale_in_url` is true
$l10n->shouldHideLocaleInUrl('fr'); // False, even if `hide_default_locale_in_url` is true
$l10n->route('about', [], true, 'en'); // `https://yourapp.com/en/about`
$l10n->route('about', [], false, 'en'); // `/en/about`
$l10n->route('about', [], true, 'fr'); // `https://yourapp.com/fr/a-propos`
// Shortcut will fallback to current locale
$l10n->route('about'); // `https://yourapp.com/en/about`
// Given the current app url is `https://yourapp.com/en/about`
$l10n->currentRoute('fr'); // `https://yourapp.com/fr/a-propos`
$l10n->currentRoute('fr', false); // `/fr/a-propos`
// Default view
$l10n->renderSwitch();
// Custom view
$l10n->renderSwitch('path.to.view');
// Custom view, with additional data
$l10n->renderSwitch('path.to.view', ['foo' => 'bar']);
// Get the Localization instance
$l10n = l10n();
// Get the current locale
$current = locale();
// Set the current locale
locale('en');
// Get supported locale
$supported = locales();