PHP Класс Mcamara\LaravelLocalization\LaravelLocalization

Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
__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)

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

Creates new instance.
public __construct ( )

checkLocaleInSupportedLocales() публичный Метод

Check if Locale exists on the supported locales array
public checkLocaleInSupportedLocales ( string | boolean $locale ) : boolean
$locale string | boolean string|bool Locale to be checked
Результат boolean is the locale supported?

checkUrl() защищенный Метод

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
Результат boolean Is the string given a valid url?

createUrlFromUri() публичный Метод

Create an url from the uri
public createUrlFromUri ( string $uri ) : string
$uri string Uri
Результат string Url for the given uri

extractAttributes() защищенный Метод

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
Результат array Array with attributes

findTranslatedRouteByPath() защищенный Метод

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
Результат string | false Key for translation, false if not exist

findTranslatedRouteByUrl() защищенный Метод

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
Результат string | false Key for translation, false if not exist

getConfigRepository() публичный Метод

Returns the config repository for this instance
public getConfigRepository ( ) : Illuminate\Config\Repository
Результат Illuminate\Config\Repository Configuration repository

getCurrentLocale() публичный Метод

Returns current language
public getCurrentLocale ( ) : string
Результат string current language

getCurrentLocaleDirection() публичный Метод

Returns current locale direction
public getCurrentLocaleDirection ( ) : string
Результат string current locale direction

getCurrentLocaleName() публичный Метод

Returns current locale name
public getCurrentLocaleName ( ) : string
Результат string current locale name

getCurrentLocaleNative() публичный Метод

Returns current locale native name
public getCurrentLocaleNative ( ) : string
Результат string current locale native name

getCurrentLocaleNativeReading() публичный Метод

Returns current language's native reading
public getCurrentLocaleNativeReading ( ) : string
Результат string current language's native reading

getCurrentLocaleRegional() публичный Метод

Returns current regional
public getCurrentLocaleRegional ( ) : string
Результат string current regional

getCurrentLocaleScript() публичный Метод

Returns current locale script
public getCurrentLocaleScript ( ) : string
Результат string current locale script

getDefaultLocale() публичный Метод

Returns default locale
public getDefaultLocale ( ) : string
Результат string

getLocalizedURL() публичный Метод

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.
Результат string | false URL translated, False if url does not exist

getNonLocalizedURL() публичный Метод

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
Результат string URL with no locale in path

getRouteNameFromAPath() публичный Метод

Returns the translation key for a given path
public getRouteNameFromAPath ( string $path ) : string | false
$path string Path to get the key translated
Результат string | false Key for translation, false if not exist

getSupportedLanguagesKeys() публичный Метод

Returns supported languages language key
public getSupportedLanguagesKeys ( ) : array
Результат array keys of supported languages

getSupportedLocales() публичный Метод

Return an array of all supported Locales
public getSupportedLocales ( ) : array
Результат array

getTranslatedRoutes() защищенный Метод

Returns translated routes
protected getTranslatedRoutes ( ) : array
Результат array translated routes

getURLFromRouteNameTranslated() публичный Метод

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)
Результат string | false URL translated

hideDefaultLocaleInURL() публичный Метод

Returns the translation key for a given path
public hideDefaultLocaleInURL ( ) : boolean
Результат boolean Returns value of hideDefaultLocaleInURL in config.

localizeURL() публичный Метод

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
Результат string URL translated

setBaseUrl() публичный Метод

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

setLocale() публичный Метод

Set and return current locale
public setLocale ( string $locale = null ) : string
$locale string Locale to set the App to (optional)
Результат string Returns locale (if route has any) or null (if route does not have a locale)

setRouteName() публичный Метод

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

setSupportedLocales() публичный Метод

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

substituteAttributesInRoute() защищенный Метод

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
Результат string route with attributes changed

transRoute() публичный Метод

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
Результат string Translated string

unparseUrl() защищенный Метод

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
Результат string Returns URL as string.

useAcceptLanguageHeader() защищенный Метод

Returns the translation key for a given path
protected useAcceptLanguageHeader ( ) : boolean
Результат boolean Returns value of useAcceptLanguageHeader in config.

Описание свойств

$app защищенное свойство

Illuminate request class.
protected Application,Illuminate\Foundation $app
Результат Illuminate\Foundation\Application

$baseUrl защищенное свойство

Illuminate request class.
protected string $baseUrl
Результат string

$configRepository защищенное свойство

Config repository.
protected Repository,Illuminate\Config $configRepository
Результат Illuminate\Config\Repository

$currentLocale защищенное свойство

Current locale
protected string $currentLocale
Результат string

$defaultLocale защищенное свойство

Default locale
protected string $defaultLocale
Результат string

$request защищенное свойство

Illuminate request class.
protected Request,Illuminate\Routing $request
Результат Illuminate\Routing\Request

$routeName защищенное свойство

Name of the translation key of the current route, it is used for url translations
protected string $routeName
Результат string

$router защищенное свойство

Illuminate router class.
protected Router,Illuminate\Routing $router
Результат Illuminate\Routing\Router

$supportedLocales защищенное свойство

Supported Locales
protected array $supportedLocales
Результат array

$translatedRoutes защищенное свойство

An array that contains all routes that should be translated
protected array $translatedRoutes
Результат array

$translator защищенное свойство

Illuminate translator class.
protected Translator,Illuminate\Translation $translator
Результат Illuminate\Translation\Translator

$view защищенное свойство

Illuminate view Factory.
protected Factory,Illuminate\View $view
Результат Illuminate\View\Factory