PHP Class Arcanedev\Localization\Localization

Author: ARCANEDEV ([email protected])
Inheritance: implements Arcanedev\Localization\Contracts\LocalizationInterface
Show file Open project: arcanedev/localization

Protected Properties

Property Type Description
$baseUrl string Base url.
$routeTranslator Arcanedev\Localization\Contracts\RouteTranslatorInterface The RouteTranslator instance.

Public Methods

Method Description
__construct ( Illuminate\Foundation\Application $app, Arcanedev\Localization\Contracts\RouteTranslatorInterface $routeTranslator, Arcanedev\Localization\Contracts\LocalesManagerInterface $localesManager ) Creates new instance.
createUrlFromUri ( string $uri ) : string Create an url from the uri.
getAllLocales ( ) : Arcanedev\Localization\Entities\LocaleCollection Get all locales.
getCurrentLocale ( ) : string Returns current language.
getCurrentLocaleDirection ( ) : string Returns current locale direction.
getCurrentLocaleEntity ( ) : Arcanedev\Localization\Entities\Locale Returns current language.
getCurrentLocaleName ( ) : string Returns current locale name.
getCurrentLocaleNative ( ) : string Returns current locale native name.
getCurrentLocaleRegional ( ) : string Returns current locale regional.
getCurrentLocaleScript ( ) : string Returns current locale script.
getDefaultLocale ( ) : string Returns default locale.
getLocalizedURL ( string | null $locale = null, string | null $url = null, array $attributes = [] ) : string | false Returns an URL adapted to $locale or current locale.
getNonLocalizedURL ( string | null $url = null ) : string It returns an URL without locale (if it has it).
getSupportedLocales ( ) : Arcanedev\Localization\Entities\LocaleCollection Return an array of all supported Locales.
getSupportedLocalesKeys ( ) : array Get supported locales keys.
getUrlFromRouteName ( string $locale, string $transKey, array $attributes = [] ) : string | false Returns an URL adapted to the route name and the locale given.
isDefaultLocaleHiddenInUrl ( ) : boolean Hide the default locale in URL ??
isLocaleSupported ( string | boolean $locale ) : boolean Check if Locale exists on the supported locales collection.
localesNavbar ( ) : string Get locales navigation bar.
localizeURL ( string | null $url = null, string | null $locale = null ) : string Returns an URL adapted to $locale or current locale.
setBaseUrl ( string $url ) : self Sets the base url for the site.
setLocale ( string | null $locale = null ) : string Set and return current locale.
setRouteNameFromRequest ( Illuminate\Http\Request $request ) Set route name from request.
setSupportedLocales ( array $supportedLocales ) : self Set the supported locales.
transRoute ( string $routeName ) : string Translate routes and save them to the translated routes array (used in the localize route filter).

Private Methods

Method Description
findTranslatedRouteByUrl ( string $url, array $attributes, string $locale ) : string | false Returns the translated route for an url and the attributes given and a locale
isLocaleSupportedOrFail ( string $locale ) Check if the locale is supported or fail if not.
request ( ) : Illuminate\Http\Request Get Request instance.

Method Details

__construct() public method

Creates new instance.
public __construct ( Illuminate\Foundation\Application $app, Arcanedev\Localization\Contracts\RouteTranslatorInterface $routeTranslator, Arcanedev\Localization\Contracts\LocalesManagerInterface $localesManager )
$app Illuminate\Foundation\Application
$routeTranslator Arcanedev\Localization\Contracts\RouteTranslatorInterface
$localesManager Arcanedev\Localization\Contracts\LocalesManagerInterface

createUrlFromUri() public method

Create an url from the uri.
public createUrlFromUri ( string $uri ) : string
$uri string
return string

getAllLocales() public method

Get all locales.
public getAllLocales ( ) : Arcanedev\Localization\Entities\LocaleCollection
return Arcanedev\Localization\Entities\LocaleCollection

getCurrentLocale() public method

Returns current language.
public getCurrentLocale ( ) : string
return string

getCurrentLocaleDirection() public method

Returns current locale direction.

getCurrentLocaleEntity() public method

Returns current language.
public getCurrentLocaleEntity ( ) : Arcanedev\Localization\Entities\Locale
return Arcanedev\Localization\Entities\Locale

getCurrentLocaleName() public method

Returns current locale name.
public getCurrentLocaleName ( ) : string
return string

getCurrentLocaleNative() public method

Returns current locale native name.
public getCurrentLocaleNative ( ) : string
return string

getCurrentLocaleRegional() public method

Returns current locale regional.
public getCurrentLocaleRegional ( ) : string
return string

getCurrentLocaleScript() public method

Returns current locale script.
public getCurrentLocaleScript ( ) : string
return string

getDefaultLocale() public method

Returns default locale.
public getDefaultLocale ( ) : string
return string

getLocalizedURL() public method

Returns an URL adapted to $locale or current locale.
public getLocalizedURL ( string | null $locale = null, string | null $url = null, array $attributes = [] ) : string | false
$locale string | null
$url string | null
$attributes array
return string | false

getNonLocalizedURL() public method

It returns an URL without locale (if it has it).
public getNonLocalizedURL ( string | null $url = null ) : string
$url string | null
return string

getSupportedLocales() public method

Return an array of all supported Locales.
public getSupportedLocales ( ) : Arcanedev\Localization\Entities\LocaleCollection
return Arcanedev\Localization\Entities\LocaleCollection

getSupportedLocalesKeys() public method

Get supported locales keys.
public getSupportedLocalesKeys ( ) : array
return array

getUrlFromRouteName() public method

Returns an URL adapted to the route name and the locale given.
public getUrlFromRouteName ( string $locale, string $transKey, array $attributes = [] ) : string | false
$locale string
$transKey string
$attributes array
return string | false

isDefaultLocaleHiddenInUrl() public method

Hide the default locale in URL ??

isLocaleSupported() public method

Check if Locale exists on the supported locales collection.
public isLocaleSupported ( string | boolean $locale ) : boolean
$locale string | boolean
return boolean

localesNavbar() public method

Get locales navigation bar.
public localesNavbar ( ) : string
return string

localizeURL() public method

Returns an URL adapted to $locale or current locale.
public localizeURL ( string | null $url = null, string | null $locale = null ) : string
$url string | null
$locale string | null
return string

setBaseUrl() public method

Sets the base url for the site.
public setBaseUrl ( string $url ) : self
$url string
return self

setLocale() public method

Set and return current locale.
public setLocale ( string | null $locale = null ) : string
$locale string | null
return string

setRouteNameFromRequest() public method

Set route name from request.
public setRouteNameFromRequest ( Illuminate\Http\Request $request )
$request Illuminate\Http\Request

setSupportedLocales() public method

Set the supported locales.
public setSupportedLocales ( array $supportedLocales ) : self
$supportedLocales array
return self

transRoute() public method

Translate routes and save them to the translated routes array (used in the localize route filter).
public transRoute ( string $routeName ) : string
$routeName string
return string

Property Details

$baseUrl protected property

Base url.
protected string $baseUrl
return string

$routeTranslator protected property

The RouteTranslator instance.
protected RouteTranslatorInterface,Arcanedev\Localization\Contracts $routeTranslator
return Arcanedev\Localization\Contracts\RouteTranslatorInterface