PHP Class Mcamara\LaravelLocalization\LaravelLocalization

Afficher le fichier Open project: mcamara/laravel-localization Class Usage Examples

Protected Properties

Свойство Type Description
$app Illuminate\Foundation\Application Illuminate request class.
$baseUrl string Illuminate request class.
$configRepository Illuminate\Config\Repository Config repository.
$currentLocale string Current locale
$defaultLocale string Default locale
$request Illuminate\Routing\Request Illuminate request class.
$routeName string Name of the translation key of the current route, it is used for url translations
$router Illuminate\Routing\Router Illuminate router class.
$supportedLocales array Supported Locales
$translatedRoutes array An array that contains all routes that should be translated
$translator Illuminate\Translation\Translator Illuminate translator class.
$view Illuminate\View\Factory Illuminate view Factory.

Méthodes publiques

Méthode Description
__construct ( ) Creates new instance.
checkLocaleInSupportedLocales ( string | boolean $locale ) : boolean Check if Locale exists on the supported locales array
createUrlFromUri ( string $uri ) : string Create an url from the uri
getConfigRepository ( ) : Illuminate\Config\Repository Returns the config repository for this instance
getCurrentLocale ( ) : string Returns current language
getCurrentLocaleDirection ( ) : string Returns current locale direction
getCurrentLocaleName ( ) : string Returns current locale name
getCurrentLocaleNative ( ) : string Returns current locale native name
getCurrentLocaleNativeReading ( ) : string Returns current language's native reading
getCurrentLocaleRegional ( ) : string Returns current regional
getCurrentLocaleScript ( ) : string Returns current locale script
getDefaultLocale ( ) : string Returns default locale
getLocalizedURL ( string | boolean $locale = null, string | false $url = null, array $attributes = [] ) : string | false Returns an URL adapted to $locale
getNonLocalizedURL ( string | false $url = null ) : string It returns an URL without locale (if it has it) Convenience function wrapping getLocalizedURL(false)
getRouteNameFromAPath ( string $path ) : string | false Returns the translation key for a given path
getSupportedLanguagesKeys ( ) : array Returns supported languages language key
getSupportedLocales ( ) : array Return an array of all supported Locales
getURLFromRouteNameTranslated ( string | boolean $locale, string $transKeyName, array $attributes = [] ) : string | false Returns an URL adapted to the route name and the locale given
hideDefaultLocaleInURL ( ) : boolean Returns the translation key for a given path
localizeURL ( string $url = null, string | boolean $locale = null ) : string Returns an URL adapted to $locale or current locale
setBaseUrl ( string $url ) Sets the base url for the site
setLocale ( string $locale = null ) : string Set and return current locale
setRouteName ( string $routeName ) Set current route name
setSupportedLocales ( array $locales ) Set and return supported locales
transRoute ( string $routeName ) : string Translate routes and save them to the translated routes array (used in the localize route filter)

Méthodes protégées

Méthode Description
checkUrl ( string $url ) : boolean Returns true if the string given is a valid url
extractAttributes ( boolean | false | null | string $url = false, string $locale = '' ) : array Extract attributes for current url
findTranslatedRouteByPath ( string $path, string $url_locale ) : string | false Returns the translated route for the path and the url given
findTranslatedRouteByUrl ( string | false | null $url, array $attributes, string $locale ) : string | false Returns the translated route for an url and the attributes given and a locale
getTranslatedRoutes ( ) : array Returns translated routes
substituteAttributesInRoute ( $attributes, string $route ) : string Change route attributes for the ones in the $attributes array
unparseUrl ( array | false $parsed_url ) : string Build URL using array data from parse_url
useAcceptLanguageHeader ( ) : boolean Returns the translation key for a given path

Method Details

__construct() public méthode

Creates new instance.
public __construct ( )

checkLocaleInSupportedLocales() public méthode

Check if Locale exists on the supported locales array
public checkLocaleInSupportedLocales ( string | boolean $locale ) : boolean
$locale string | boolean string|bool Locale to be checked
Résultat boolean is the locale supported?

checkUrl() protected méthode

Returns true if the string given is a valid url
protected checkUrl ( string $url ) : boolean
$url string String to check if it is a valid url
Résultat boolean Is the string given a valid url?

createUrlFromUri() public méthode

Create an url from the uri
public createUrlFromUri ( string $uri ) : string
$uri string Uri
Résultat string Url for the given uri

extractAttributes() protected méthode

Extract attributes for current url
protected extractAttributes ( boolean | false | null | string $url = false, string $locale = '' ) : array
$url boolean | false | null | string to extract attributes, if not present, the system will look for attributes in the current call
$locale string
Résultat array Array with attributes

findTranslatedRouteByPath() protected méthode

Returns the translated route for the path and the url given
protected findTranslatedRouteByPath ( string $path, string $url_locale ) : string | false
$path string Path to check if it is a translated route
$url_locale string Language to check if the path exists
Résultat string | false Key for translation, false if not exist

findTranslatedRouteByUrl() protected méthode

Returns the translated route for an url and the attributes given and a locale
protected findTranslatedRouteByUrl ( string | false | null $url, array $attributes, string $locale ) : string | false
$url string | false | null Url to check if it is a translated route
$attributes array Attributes to check if the url exists in the translated routes array
$locale string Language to check if the url exists
Résultat string | false Key for translation, false if not exist

getConfigRepository() public méthode

Returns the config repository for this instance
public getConfigRepository ( ) : Illuminate\Config\Repository
Résultat Illuminate\Config\Repository Configuration repository

getCurrentLocale() public méthode

Returns current language
public getCurrentLocale ( ) : string
Résultat string current language

getCurrentLocaleDirection() public méthode

Returns current locale direction
public getCurrentLocaleDirection ( ) : string
Résultat string current locale direction

getCurrentLocaleName() public méthode

Returns current locale name
public getCurrentLocaleName ( ) : string
Résultat string current locale name

getCurrentLocaleNative() public méthode

Returns current locale native name
public getCurrentLocaleNative ( ) : string
Résultat string current locale native name

getCurrentLocaleNativeReading() public méthode

Returns current language's native reading
public getCurrentLocaleNativeReading ( ) : string
Résultat string current language's native reading

getCurrentLocaleRegional() public méthode

Returns current regional
public getCurrentLocaleRegional ( ) : string
Résultat string current regional

getCurrentLocaleScript() public méthode

Returns current locale script
public getCurrentLocaleScript ( ) : string
Résultat string current locale script

getDefaultLocale() public méthode

Returns default locale
public getDefaultLocale ( ) : string
Résultat string

getLocalizedURL() public méthode

Returns an URL adapted to $locale
public getLocalizedURL ( string | boolean $locale = null, string | false $url = null, array $attributes = [] ) : string | false
$locale string | boolean Locale to adapt, false to remove locale
$url string | false URL to adapt in the current language. If not passed, the current url would be taken.
$attributes array Attributes to add to the route, if empty, the system would try to extract them from the url.
Résultat string | false URL translated, False if url does not exist

getNonLocalizedURL() public méthode

It returns an URL without locale (if it has it) Convenience function wrapping getLocalizedURL(false)
public getNonLocalizedURL ( string | false $url = null ) : string
$url string | false URL to clean, if false, current url would be taken
Résultat string URL with no locale in path

getRouteNameFromAPath() public méthode

Returns the translation key for a given path
public getRouteNameFromAPath ( string $path ) : string | false
$path string Path to get the key translated
Résultat string | false Key for translation, false if not exist

getSupportedLanguagesKeys() public méthode

Returns supported languages language key
public getSupportedLanguagesKeys ( ) : array
Résultat array keys of supported languages

getSupportedLocales() public méthode

Return an array of all supported Locales
public getSupportedLocales ( ) : array
Résultat array

getTranslatedRoutes() protected méthode

Returns translated routes
protected getTranslatedRoutes ( ) : array
Résultat array translated routes

getURLFromRouteNameTranslated() public méthode

Returns an URL adapted to the route name and the locale given
public getURLFromRouteNameTranslated ( string | boolean $locale, string $transKeyName, array $attributes = [] ) : string | false
$locale string | boolean Locale to adapt
$transKeyName string Translation key name of the url to adapt
$attributes array Attributes for the route (only needed if transKeyName needs them)
Résultat string | false URL translated

hideDefaultLocaleInURL() public méthode

Returns the translation key for a given path
public hideDefaultLocaleInURL ( ) : boolean
Résultat boolean Returns value of hideDefaultLocaleInURL in config.

localizeURL() public méthode

Returns an URL adapted to $locale or current locale
public localizeURL ( string $url = null, string | boolean $locale = null ) : string
$url string URL to adapt. If not passed, the current url would be taken.
$locale string | boolean Locale to adapt, false to remove locale
Résultat string URL translated

setBaseUrl() public méthode

Sets the base url for the site
public setBaseUrl ( string $url )
$url string Base url for the site

setLocale() public méthode

Set and return current locale
public setLocale ( string $locale = null ) : string
$locale string Locale to set the App to (optional)
Résultat string Returns locale (if route has any) or null (if route does not have a locale)

setRouteName() public méthode

Set current route name
public setRouteName ( string $routeName )
$routeName string current route name

setSupportedLocales() public méthode

Set and return supported locales
public setSupportedLocales ( array $locales )
$locales array Locales that the App supports

substituteAttributesInRoute() protected méthode

Change route attributes for the ones in the $attributes array
protected substituteAttributesInRoute ( $attributes, string $route ) : string
$attributes array Array of attributes
$route string string route to substitute
Résultat string route with attributes changed

transRoute() public méthode

Translate routes and save them to the translated routes array (used in the localize route filter)
public transRoute ( string $routeName ) : string
$routeName string Key of the translated string
Résultat string Translated string

unparseUrl() protected méthode

Build URL using array data from parse_url
protected unparseUrl ( array | false $parsed_url ) : string
$parsed_url array | false Array of data from parse_url function
Résultat string Returns URL as string.

useAcceptLanguageHeader() protected méthode

Returns the translation key for a given path
protected useAcceptLanguageHeader ( ) : boolean
Résultat boolean Returns value of useAcceptLanguageHeader in config.

Property Details

$app protected_oe property

Illuminate request class.
protected Application,Illuminate\Foundation $app
Résultat Illuminate\Foundation\Application

$baseUrl protected_oe property

Illuminate request class.
protected string $baseUrl
Résultat string

$configRepository protected_oe property

Config repository.
protected Repository,Illuminate\Config $configRepository
Résultat Illuminate\Config\Repository

$currentLocale protected_oe property

Current locale
protected string $currentLocale
Résultat string

$defaultLocale protected_oe property

Default locale
protected string $defaultLocale
Résultat string

$request protected_oe property

Illuminate request class.
protected Request,Illuminate\Routing $request
Résultat Illuminate\Routing\Request

$routeName protected_oe property

Name of the translation key of the current route, it is used for url translations
protected string $routeName
Résultat string

$router protected_oe property

Illuminate router class.
protected Router,Illuminate\Routing $router
Résultat Illuminate\Routing\Router

$supportedLocales protected_oe property

Supported Locales
protected array $supportedLocales
Résultat array

$translatedRoutes protected_oe property

An array that contains all routes that should be translated
protected array $translatedRoutes
Résultat array

$translator protected_oe property

Illuminate translator class.
protected Translator,Illuminate\Translation $translator
Résultat Illuminate\Translation\Translator

$view protected_oe property

Illuminate view Factory.
protected Factory,Illuminate\View $view
Résultat Illuminate\View\Factory