PHP Class i18n, php-i18n

显示文件 Open project: philipp15b/php-i18n Class Usage Examples

Protected Properties

Property Type Description
$appliedLang
$cacheFilePath
$cachePath string Cache file path This is the path for all the cache files. Best is an empty directory with no other files in it.
$fallbackLang string Remember to create a language file for the fallback!!
$filePath string Language file path This is the path for the language files. You must use the '{LANGUAGE}' placeholder for the language or the script wont find any language files.
$forcedLang string Forced language If you want to force a specific language define it here.
$isInitialized
$langFilePath
$mergeFallback boolean Merge in fallback language Whether to merge current language's strings with the strings of the fallback language ($fallbackLang).
$prefix string The class name of the compiled class that contains the translated texts.
$sectionSeperator string For example, if you have a string 'greeting' in a section 'welcomepage' you will can access it via 'L::welcomepage_greeting'. If you changed it to 'ABC' you could access your string via 'L::welcomepageABCgreeting'
$userLangs array Normally, if you use the getUserLangs-method this array will be filled in like this: 1. Forced language 2. Language in $_GET['lang'] 3. Language in $_SESSION['lang'] 4. Fallback language

Public Methods

Method Description
__construct ( $filePath = NULL, $cachePath = NULL, $fallbackLang = NULL, $prefix = NULL ) Constructor The constructor sets all important settings. All params are optional, you can set the options via extra functions too.
getAppliedLang ( )
getCachePath ( )
getFallbackLang ( )
getUserLangs ( ) : array getUserLangs() Returns the user languages Normally it returns an array like this: 1. Forced language 2. Language in $_GET['lang'] 3. Language in $_SESSION['lang'] 4. HTTP_ACCEPT_LANGUAGE 5. Fallback language Note: duplicate values are deleted.
init ( )
isInitialized ( )
setCachePath ( $cachePath )
setFallbackLang ( $fallbackLang )
setFilePath ( $filePath )
setForcedLang ( $forcedLang )
setMergeFallback ( $mergeFallback )
setPrefix ( $prefix )
setSectionSeperator ( $sectionSeperator )

Protected Methods

Method Description
compile ( $config, $prefix = '' ) Recursively compile an associative array to PHP code.
fail_after_init ( )
getConfigFilename ( $langcode )
load ( $filename )

Private Methods

Method Description
array_extend ( $a, $b ) Something of a sane version of PHP's array_merge

Method Details

__construct() public method

Constructor The constructor sets all important settings. All params are optional, you can set the options via extra functions too.
public __construct ( $filePath = NULL, $cachePath = NULL, $fallbackLang = NULL, $prefix = NULL )

compile() protected method

Recursively compile an associative array to PHP code.
protected compile ( $config, $prefix = '' )

fail_after_init() protected method

protected fail_after_init ( )

getAppliedLang() public method

public getAppliedLang ( )

getCachePath() public method

public getCachePath ( )

getConfigFilename() protected method

protected getConfigFilename ( $langcode )

getFallbackLang() public method

public getFallbackLang ( )

getUserLangs() public method

getUserLangs() Returns the user languages Normally it returns an array like this: 1. Forced language 2. Language in $_GET['lang'] 3. Language in $_SESSION['lang'] 4. HTTP_ACCEPT_LANGUAGE 5. Fallback language Note: duplicate values are deleted.
public getUserLangs ( ) : array
return array with the user languages sorted by priority.

init() public method

public init ( )

isInitialized() public method

public isInitialized ( )

load() protected method

protected load ( $filename )

setCachePath() public method

public setCachePath ( $cachePath )

setFallbackLang() public method

public setFallbackLang ( $fallbackLang )

setFilePath() public method

public setFilePath ( $filePath )

setForcedLang() public method

public setForcedLang ( $forcedLang )

setMergeFallback() public method

public setMergeFallback ( $mergeFallback )

setPrefix() public method

public setPrefix ( $prefix )

setSectionSeperator() public method

public setSectionSeperator ( $sectionSeperator )

Property Details

$appliedLang protected_oe property

protected $appliedLang

$cacheFilePath protected_oe property

protected $cacheFilePath

$cachePath protected_oe property

Cache file path This is the path for all the cache files. Best is an empty directory with no other files in it.
protected string $cachePath
return string

$fallbackLang protected_oe property

Remember to create a language file for the fallback!!
protected string $fallbackLang
return string

$filePath protected_oe property

Language file path This is the path for the language files. You must use the '{LANGUAGE}' placeholder for the language or the script wont find any language files.
protected string $filePath
return string

$forcedLang protected_oe property

Forced language If you want to force a specific language define it here.
protected string $forcedLang
return string

$isInitialized protected_oe property

protected $isInitialized

$langFilePath protected_oe property

protected $langFilePath

$mergeFallback protected_oe property

Merge in fallback language Whether to merge current language's strings with the strings of the fallback language ($fallbackLang).
protected bool $mergeFallback
return boolean

$prefix protected_oe property

The class name of the compiled class that contains the translated texts.
protected string $prefix
return string

$sectionSeperator protected_oe property

For example, if you have a string 'greeting' in a section 'welcomepage' you will can access it via 'L::welcomepage_greeting'. If you changed it to 'ABC' you could access your string via 'L::welcomepageABCgreeting'
protected string $sectionSeperator
return string

$userLangs protected_oe property

Normally, if you use the getUserLangs-method this array will be filled in like this: 1. Forced language 2. Language in $_GET['lang'] 3. Language in $_SESSION['lang'] 4. Fallback language
protected array $userLangs
return array