Class Lang
Core router: - main store for all routes - application request routing process before request dispatching in core - currently matched route store - application url completing - by configured routes into mod_rewrite form - or into query string form, containing controller and action params - params query string building - primitive param value or array value representation possible
- MvcCore\Router
-
MvcCore\Ext\Router\Lang
public
|
#
SetAllowedLangs( )
Set international lowercase language code(s), allowed to use in your application. Default language is always allowed. |
public
|
#
AddAllowedLangs( )
Add international lowercase language code(s), allowed to use in your application. Default language is always allowed. |
public
|
#
SetDefaultLang( string $defaultLang )
Set default lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session. |
public
|
|
public
|
#
SetSessionExpirationSeconds( integer $sessionExpirationSeconds = 3600 )
Session expiration in seconds, by default - one hour. |
public
|
#
SetStricModeBySession( boolean $stricModeBySession = TRUE )
If TRUE, language is not possible to switch by different request url path begin, because for every different url path begin than session record is user automaticly redirected to url path begin by session. If TRUE, language version is possible to change only by special $_GET param called 'switch_lang=..' in query string. If not configured, FALSE by default. |
public
|
#
SetKeepDefaultLangPath( mixed $keepDefaultLangPath = TRUE )
If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default. |
public
|
#
SetFirstRequestStrictlyByUserAgent( boolean $firstRequestStrictlyByUserAgent = TRUE )
If TRUE, first request language will be strictly recognized by user agent http header 'Acept-Language', not by requested url. First or not first request is detected by session. If not configured, FALSE by default. |
public
|
#
SetAllowNonLocalizedRoutes( boolean $allowNonLocalizedRoutes = TRUE )
If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default. |
public
|
#
AddRoute( array|stdClass|
Append or prepend new request route. Route definition array shoud be array with route configuration definition, stdClass with route configuration definition or \MvcCore\Route instance. In configuration definition is required route name, controller, action, pattern and if pattern contains regexp groups, its necessary also to define route reverse. Route name should be defined as 'Controller:Action' string or any custom route name, but then there is necessary to specify controller name and action name inside route array/stdClass configuration or route instance. |
protected
|
|
protected
string
|
#
getRouteLocalizedRecord(
Get route non-localized or localized record - 'Pattern' and 'Reverse' |
public static
|
|
protected
string
|
#
urlByRoute( string $controllerActionOrRouteName, array $params )
Complete url by route instance reverse info |
protected
|
#
processLangVersion(
Detect language version by configured rules, set up detected version to current context, into request and into session and redirect if necessary. |
protected
|
#
setUpDetectedLangAndRedirectIfNecessary( string $detectedLang )
Store detected language in session, in request and in router. If detected is different than request version - redirect to detected version. Else if original request version is different than request version and boolean switch $this->allowNonLocalizedRoutes is true, redirect to default lang. |
protected
|
#
prepareProcessing(
Prepare language processing: - store request object reference - store request path into request original path - try to complete switching param from $_GET - try to complete request lang - try to complete session lang |
protected
|
#
redirectToDifferentLangVersion( string $targetLang )
Redirect to different language path version, only by changing first path element to different value. If router is configured to use default lang root path, keep it. |
protected
|
#
setUpRequestLangFromUrl( )
Try to set up lang from request, if there is any lang, correct request path, if thre is no request language, set up default lang. |
protected
|
#
setUpAllowedLangs( )
Add default language into allowed languages and change all array values into keys, set all values as 1 (int). |
protected
|
#
setUpSession( )
If session namespace by this class is not initialized, init namespace and move expiration (to next hour by default) |
protected
|
|
protected
array
|
#
parseUserAgentLangList( string $languagesList )
Parse list of comma separated language tags and sort it by the quality value |
string |
VERSION
MvcCore Extension - Router Lang - version: Comparation by PHP function version_compare(); |
#
'4.2.0'
|
string |
LANG_URL_PARAM
Key name for language in second argument $params in $router->Url(); method, to tell $router->Url() method to generate different language url. |
#
'lang'
|
string |
LANG_SWITCH_URL_PARAM
Special $_GET param name for session strict mode, how to change site language version. |
#
'switch_lang'
|
public
string|array
|
$Pattern
Route preg_match pattern in classic PHP form: array('en' => "#^/url-begin/([^/])/([^/])/(.)#", 'de' => "#^/url-beginn/([^/])/([^/])/(.)#",); |
#
''
|
public
string|array
|
$Reverse
Route reverse address form from preg_replace pattern in form: array('en' => "/url-begin/{%first}/{%second}/{%third}", 'de' => "/url-beginn/{%first}/{%second}/{%third}",); |
#
''
|
public
string
|
$DefaultLang
Default language, two lowercase characters, internaltional language code, lang to use in cases, when is not possible to detect lang from url, not possible to detect lang from 'Accept-Language' http header or not possible to get from session. |
#
'en'
|
public
string
|
$Lang
Result language, two lowercase characters, internaltional language code. Example: 'en' | 'fr' | 'de'... |
#
''
|
public
integer
|
$SessionExpirationSeconds
Session expiration seconds for remembering detected lang version by user agent. Session record is always used to compare if user is requesting different media site version then he has in session - if there is difference - user is redirected to session media site version and this seconds is time to remember that sessio record for described redirection. |
#
3600
|
protected
|
$session
Session record is always used to compare if user is requesting different lang version then he has in session - if there is difference - user is redirected to session lang version. |
#
NULL
|
protected
string
|
$sessionLang
Lang founded in session. |
#
''
|
protected
string
|
$requestLang
Lang founded in request. |
#
''
|
protected
string
|
$switchUriParamLang
Lang value in special $_GET param if session mode is strict. |
#
''
|
protected
string
|
$requestLangNotAllowed
If any, lang value in request, in url, not allowed to work with. |
#
''
|
protected
boolean
|
$stricModeBySession
If true, process lang version strictly by session stored version, so if request contains some version and in session is different, redirect user to session version value adress, only when lang switching param is contained in $_GET, switch the version in session. If false, process lang version more benevolently, so if request contains some lang and in session is different, store in session lang version from request and do not redirect user. |
#
FALSE
|
protected
boolean
|
$keepDefaultLangPath
If TRUE and language is necessary to request into default language url version, there is target url path completed into '/'+$this->DefaultLang, not to '/' (slash) only. If FALSE and language is necessary to request into default language url version, there is target url path completed only to '/' (slash). If not configured, FALSE by default. |
#
FALSE
|
protected
boo
|
$allowNonLocalizedRoutes
If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default. |
#
TRUE
|
protected
boolean
|
$firstRequestStrictlyByUserAgent
If TRUE, redirect request to default language version if lang in request is not allowed. If not configured, TRUE by default. |
#
FALSE
|
protected
array
|
$allowedLangs
Allowed language codes to use in your application, default lang will be allowed automaticly. |
#
array()
|
$currentRoute,
$instance,
$request,
$routeToDefaultIfNotMatch,
$routes,
$urlRoutes
|