PHP Class Stevebauman\Translation\Translation

Inheritance: implements Stevebauman\Translation\Contracts\Translation
显示文件 Open project: stevebauman/translation

Protected Properties

Property Type Description
$cache Illuminate\Cache\CacheManager Holds the current cache instance.
$client Stevebauman\Translation\Contracts\Client Holds the translation client.
$config Illuminate\Config\Repository Holds the current config instance.
$locale string Holds the application locale.
$localeModel Illuminate\Database\Eloquent\Model Holds the locale model.
$request Illuminate\Http\Request Holds the current request instance.
$translationModel Illuminate\Database\Eloquent\Model Holds the translation model.

Public Methods

Method Description
__construct ( Illuminate\Contracts\Foundation\Application $app )
getAppLocale ( )
getDefaultTranslation ( $text )
getLocale ( )
getRoutePrefix ( )
setLocale ( $code = '' )
translate ( $text = '', $replacements = [], $toLocale = '', $runOnce = false )

Protected Methods

Method Description
autoTranslateEnabled ( ) : boolean Returns the auto translate configuration option.
compressString ( $string ) : string Calculates the md5 hash of a string.
firstOrCreateLocale ( string $code ) : Model Retrieves or creates a locale from the specified code.
firstOrCreateTranslation ( Model $locale, string $text, Model $parentTranslation = null ) : Model Creates a translation.
getCacheLocale ( string $code ) : boolean Retrieves a cached locale from the specified locale code.
getCacheTranslation ( Model $locale, string $text ) : boolean | Model Retrieves the cached translation from the specified locale and text.
getConfigCacheTime ( ) : string | integer Returns the cache time set from the configuration file.
getConfigClient ( ) : string Returns the translation client from the configuration.
getConfigDefaultLocale ( ) : string Returns the default locale from the configuration.
getConfigLocaleByCode ( string $code ) : string Returns a the english name of the locale code entered from the config file.
getConfigLocaleModel ( ) : string Returns the locale model from the configuration.
getConfigLocales ( ) : array Returns the array of configuration locales.
getConfigRequestSegment ( ) : integer Returns the request segment to retrieve the locale from.
getConfigTranslationModel ( ) : string Returns the translation model from the configuration.
getTranslationCacheId ( Model $locale, string $text ) : string Returns a unique translation code by compressing the text using a PHP compression function.
makeReplacements ( string $text, array $replacements ) : string Make the place-holder replacements on the specified text.
makeTranslationSafePlaceholder ( string $key = '' ) : string Makes a placeholder by the specified key.
makeTranslationSafePlaceholders ( string $text, array $replace = [] ) : mixed Replaces laravel translation placeholders with google translate safe placeholders. Ex:.
removeCacheLocale ( string $code ) Remove a locale from the cache.
removeCacheTranslation ( Model $translation ) Remove the translation from the cache manually.
setCacheLocale ( Model $locale ) Sets a cache key to the specified locale.
setCacheTime ( integer $time ) Sets the time to store the translations and locales in cache.
setCacheTranslation ( Model $translation ) Sets a cache key to the specified locale and text.
validateText ( $text ) : boolean Validates the inserted text to make sure it's a string.

Method Details

__construct() public method

public __construct ( Illuminate\Contracts\Foundation\Application $app )
$app Illuminate\Contracts\Foundation\Application

autoTranslateEnabled() protected method

Returns the auto translate configuration option.
protected autoTranslateEnabled ( ) : boolean
return boolean

compressString() protected method

Used for storing cache keys for translations.
protected compressString ( $string ) : string
$string
return string

firstOrCreateLocale() protected method

Retrieves or creates a locale from the specified code.
protected firstOrCreateLocale ( string $code ) : Model
$code string
return Illuminate\Database\Eloquent\Model

firstOrCreateTranslation() protected method

Creates a translation.
protected firstOrCreateTranslation ( Model $locale, string $text, Model $parentTranslation = null ) : Model
$locale Illuminate\Database\Eloquent\Model
$text string
$parentTranslation Illuminate\Database\Eloquent\Model
return Illuminate\Database\Eloquent\Model

getAppLocale() public method

public getAppLocale ( )

getCacheLocale() protected method

Retrieves a cached locale from the specified locale code.
protected getCacheLocale ( string $code ) : boolean
$code string
return boolean

getCacheTranslation() protected method

Retrieves the cached translation from the specified locale and text.
protected getCacheTranslation ( Model $locale, string $text ) : boolean | Model
$locale Illuminate\Database\Eloquent\Model
$text string
return boolean | Illuminate\Database\Eloquent\Model

getConfigCacheTime() protected method

Returns the cache time set from the configuration file.
protected getConfigCacheTime ( ) : string | integer
return string | integer

getConfigClient() protected method

Returns the translation client from the configuration.
protected getConfigClient ( ) : string
return string

getConfigDefaultLocale() protected method

Returns the default locale from the configuration.
protected getConfigDefaultLocale ( ) : string
return string

getConfigLocaleByCode() protected method

Returns a the english name of the locale code entered from the config file.
protected getConfigLocaleByCode ( string $code ) : string
$code string
return string

getConfigLocaleModel() protected method

Returns the locale model from the configuration.
protected getConfigLocaleModel ( ) : string
return string

getConfigLocales() protected method

Returns the array of configuration locales.
protected getConfigLocales ( ) : array
return array

getConfigRequestSegment() protected method

Returns the request segment to retrieve the locale from.
protected getConfigRequestSegment ( ) : integer
return integer

getConfigTranslationModel() protected method

Returns the translation model from the configuration.
protected getConfigTranslationModel ( ) : string
return string

getDefaultTranslation() public method

public getDefaultTranslation ( $text )

getLocale() public method

public getLocale ( )

getRoutePrefix() public method

public getRoutePrefix ( )

getTranslationCacheId() protected method

Returns a unique translation code by compressing the text using a PHP compression function.
protected getTranslationCacheId ( Model $locale, string $text ) : string
$locale Illuminate\Database\Eloquent\Model
$text string
return string

makeReplacements() protected method

Make the place-holder replacements on the specified text.
protected makeReplacements ( string $text, array $replacements ) : string
$text string
$replacements array
return string

makeTranslationSafePlaceholder() protected method

Makes a placeholder by the specified key.
protected makeTranslationSafePlaceholder ( string $key = '' ) : string
$key string
return string

makeTranslationSafePlaceholders() protected method

Converts: :name Into: __name__
protected makeTranslationSafePlaceholders ( string $text, array $replace = [] ) : mixed
$text string
$replace array
return mixed

removeCacheLocale() protected method

Remove a locale from the cache.
protected removeCacheLocale ( string $code )
$code string

removeCacheTranslation() protected method

Remove the translation from the cache manually.
protected removeCacheTranslation ( Model $translation )
$translation Illuminate\Database\Eloquent\Model

setCacheLocale() protected method

Sets a cache key to the specified locale.
protected setCacheLocale ( Model $locale )
$locale Illuminate\Database\Eloquent\Model

setCacheTime() protected method

Sets the time to store the translations and locales in cache.
protected setCacheTime ( integer $time )
$time integer

setCacheTranslation() protected method

Sets a cache key to the specified locale and text.
protected setCacheTranslation ( Model $translation )
$translation Illuminate\Database\Eloquent\Model

setLocale() public method

public setLocale ( $code = '' )

translate() public method

public translate ( $text = '', $replacements = [], $toLocale = '', $runOnce = false )

validateText() protected method

Validates the inserted text to make sure it's a string.
protected validateText ( $text ) : boolean
$text
return boolean

Property Details

$cache protected_oe property

Holds the current cache instance.
protected CacheManager,Illuminate\Cache $cache
return Illuminate\Cache\CacheManager

$client protected_oe property

Holds the translation client.
protected Client,Stevebauman\Translation\Contracts $client
return Stevebauman\Translation\Contracts\Client

$config protected_oe property

Holds the current config instance.
protected Repository,Illuminate\Config $config
return Illuminate\Config\Repository

$locale protected_oe property

Holds the application locale.
protected string $locale
return string

$localeModel protected_oe property

Holds the locale model.
protected Model,Illuminate\Database\Eloquent $localeModel
return Illuminate\Database\Eloquent\Model

$request protected_oe property

Holds the current request instance.
protected Request,Illuminate\Http $request
return Illuminate\Http\Request

$translationModel protected_oe property

Holds the translation model.
protected Model,Illuminate\Database\Eloquent $translationModel
return Illuminate\Database\Eloquent\Model