PHP 클래스 codemix\localeurls\UrlManager

This class extends Yii's UrlManager and adds features to detect the language from the URL or from browser settings transparently. It also can persist the language in the user session and optionally in a cookie. It also adds the language parameter to any created URL.
상속: extends yii\web\UrlManager
파일 보기 프로젝트 열기: codemix/yii2-localeurls 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$enableDefaultLanguageUrlCode whether the default language should use an URL code like any other configured language. By default this is false, so for URLs without a language code the default language is assumed. In addition any request to an URL that contains the default language code will be redirected to the same URL without a language code. So if the default language is fr and a user requests /fr/some/page he gets redirected to /some/page. This way the persistet language can be reset to the default language. If this is true, then an URL that does not contain any language code will be redirected to the same URL with default language code. So if for example the default language is fr, then any request to /some/page will be redirected to /fr/some/page.
$enableLanguageDetection whether to detect the app language from the HTTP headers (i.e. browser settings). Default is true.
$enableLanguagePersistence whether to store the detected language in session and (optionally) a cookie. If this is true (default) and a returning user tries to access any URL without a language prefix, he'll be redirected to the respective stored language URL (e.g. /some/page -> /fr/some/page).
$enableLocaleUrls whether to enable locale URL specific features
$enablePrettyUrl
$ignoreLanguageUrlPatterns list of route and URL regex patterns to ignore during language processing. The keys of the array are patterns for routes, the values are patterns for URLs. Route patterns are checked during URL creation. If a pattern matches, no language parameter will be added to the created URL. URL patterns are checked during processing incoming requests. If a pattern matches, the language processing will be skipped for that URL. Examples: ~~~php [ '#^site/(login|register)#' => '#^(login|register)#' '#^api/#' => '#^api/#', ] ~~~
$keepUppercaseLanguageCode whether to keep upper case language codes in URL. Default is false wich will e.g. redirect de-AT to de-at.
$languageCookieDuration number of seconds how long the language information should be stored in cookie, if $enableLanguagePersistence is true. Set to false to disable the language cookie completely. Default is 30 days.
$languageCookieName the name of the language cookie. Default is '_language'.
$languageCookieOptions configuration options for the language cookie. Note that $languageCookieName and $languageCookeDuration will override any name and expire settings provided here.
$languageParam if a parameter with this name is passed to any createUrl() method, the created URL will use the language specified there. URLs created this way can be used to switch to a different language. If no such parameter is used, the currently detected application language is used.
$languageSessionKey the name of the session key that is used to store the language. Default is '_language'.
$languages list of available language codes. More specific patterns should come first, e.g. 'en_us' before 'en'. This can also contain mapping of => , e.g. 'english' => 'en'.

보호된 프로퍼티들

프로퍼티 타입 설명
$_defaultLanguage the language that was initially set in the application configuration
$_processed whether locale URL was processed
$_request yii\web\Request

공개 메소드들

메소드 설명
createUrl ( $params )
getDefaultLanguage ( ) : string
init ( )
parseRequest ( $request )

보호된 메소드들

메소드 설명
matchCode ( string $code ) : array Tests whether the given code matches any of the configured languages.
processLocaleUrl ( $request ) Checks for a language or locale parameter in the URL and rewrites the pathInfo if found.
redirectToLanguage ( string $language ) Redirect to the current URL with given language code applied

메소드 상세

createUrl() 공개 메소드

public createUrl ( $params )

getDefaultLanguage() 공개 메소드

public getDefaultLanguage ( ) : string
리턴 string the `language` option that was initially set in the application config file, before it was modified by this component.

init() 공개 메소드

public init ( )

matchCode() 보호된 메소드

If the code is a single language code, and matches either - an exact language as configured (ll) - a language with a country wildcard (ll-*) this language code is returned. If the code also contains a country code, and matches either - an exact language/country code as configured (ll-CC) - a language with a country wildcard (ll-*) the code with uppercase country is returned. If only the language part matches a configured language, that language is returned.
protected matchCode ( string $code ) : array
$code string the code to match
리턴 array of [language, country], [language, null] or [null, null] if no match

parseRequest() 공개 메소드

public parseRequest ( $request )

processLocaleUrl() 보호된 메소드

If no parameter is found it will try to detect the language from persistent storage (session / cookie) or from browser settings.
protected processLocaleUrl ( $request )

redirectToLanguage() 보호된 메소드

Redirect to the current URL with given language code applied
protected redirectToLanguage ( string $language )
$language string the language code to add. Can also be empty to not add any language code.

프로퍼티 상세

$_defaultLanguage 보호되어 있는 프로퍼티

the language that was initially set in the application configuration
protected $_defaultLanguage

$_processed 보호되어 있는 프로퍼티

whether locale URL was processed
protected $_processed

$_request 보호되어 있는 프로퍼티

protected Request,yii\web $_request
리턴 yii\web\Request

$enableDefaultLanguageUrlCode 공개적으로 프로퍼티

whether the default language should use an URL code like any other configured language. By default this is false, so for URLs without a language code the default language is assumed. In addition any request to an URL that contains the default language code will be redirected to the same URL without a language code. So if the default language is fr and a user requests /fr/some/page he gets redirected to /some/page. This way the persistet language can be reset to the default language. If this is true, then an URL that does not contain any language code will be redirected to the same URL with default language code. So if for example the default language is fr, then any request to /some/page will be redirected to /fr/some/page.
public $enableDefaultLanguageUrlCode

$enableLanguageDetection 공개적으로 프로퍼티

whether to detect the app language from the HTTP headers (i.e. browser settings). Default is true.
public $enableLanguageDetection

$enableLanguagePersistence 공개적으로 프로퍼티

whether to store the detected language in session and (optionally) a cookie. If this is true (default) and a returning user tries to access any URL without a language prefix, he'll be redirected to the respective stored language URL (e.g. /some/page -> /fr/some/page).
public $enableLanguagePersistence

$enableLocaleUrls 공개적으로 프로퍼티

whether to enable locale URL specific features
public $enableLocaleUrls

$enablePrettyUrl 공개적으로 프로퍼티

public $enablePrettyUrl

$ignoreLanguageUrlPatterns 공개적으로 프로퍼티

list of route and URL regex patterns to ignore during language processing. The keys of the array are patterns for routes, the values are patterns for URLs. Route patterns are checked during URL creation. If a pattern matches, no language parameter will be added to the created URL. URL patterns are checked during processing incoming requests. If a pattern matches, the language processing will be skipped for that URL. Examples: ~~~php [ '#^site/(login|register)#' => '#^(login|register)#' '#^api/#' => '#^api/#', ] ~~~
public $ignoreLanguageUrlPatterns

$keepUppercaseLanguageCode 공개적으로 프로퍼티

whether to keep upper case language codes in URL. Default is false wich will e.g. redirect de-AT to de-at.
public $keepUppercaseLanguageCode

$languageCookieDuration 공개적으로 프로퍼티

number of seconds how long the language information should be stored in cookie, if $enableLanguagePersistence is true. Set to false to disable the language cookie completely. Default is 30 days.
public $languageCookieDuration

$languageCookieName 공개적으로 프로퍼티

the name of the language cookie. Default is '_language'.
public $languageCookieName

$languageCookieOptions 공개적으로 프로퍼티

configuration options for the language cookie. Note that $languageCookieName and $languageCookeDuration will override any name and expire settings provided here.
public $languageCookieOptions

$languageParam 공개적으로 프로퍼티

if a parameter with this name is passed to any createUrl() method, the created URL will use the language specified there. URLs created this way can be used to switch to a different language. If no such parameter is used, the currently detected application language is used.
public $languageParam

$languageSessionKey 공개적으로 프로퍼티

the name of the session key that is used to store the language. Default is '_language'.
public $languageSessionKey

$languages 공개적으로 프로퍼티

list of available language codes. More specific patterns should come first, e.g. 'en_us' before 'en'. This can also contain mapping of => , e.g. 'english' => 'en'.
public $languages