PHP Trait Dimsav\Translatable\Translatable

ファイルを表示 Open project: dimsav/laravel-translatable

Public Methods

Method Description
__isset ( $key ) : boolean
deleteTranslations ( string | array | null $locales = null ) Deletes all translations for this model.
fill ( array $attributes )
getAttribute ( string $key ) : mixed
getLocaleKey ( ) : string
getNewTranslation ( string $locale ) : Model
getRelationKey ( ) : string
getTranslation ( string | null $locale = null, boolean $withFallback = null ) : Model | null
getTranslationModelName ( ) : string
getTranslationModelNameDefault ( ) : string
hasTranslation ( string | null $locale = null ) : boolean
isTranslationAttribute ( string $key ) : boolean
save ( array $options = [] ) : boolean
scopeListsTranslations ( Builder $query, string $translationField ) Adds scope to get a list of translated attributes, using the current locale.
scopeNotTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
scopeTranslated ( Builder $query ) : Builder | static
scopeTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
scopeWhereTranslation ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static This scope filters results by checking the translation fields.
scopeWhereTranslationLike ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static This scope filters results by checking the translation fields.
scopeWithTranslation ( Builder $query ) This scope eager loads the translations for the default and the fallback locale only.
setAttribute ( string $key, mixed $value )
toArray ( ) : array
translate ( string | null $locale = null, boolean $withFallback = false ) : Model | null Alias for getTranslation().
translateOrDefault ( string $locale ) : Model | null Alias for getTranslation().
translateOrNew ( string $locale ) : Model | null Alias for getTranslationOrNew().
translations ( ) : Illuminate\Database\Eloquent\Relations\HasMany

Protected Methods

Method Description
getLocaleSeparator ( ) : string
getLocales ( ) : array
getTranslationOrNew ( string $locale ) : Model | null
isKeyALocale ( string $key ) : boolean
isTranslationDirty ( Model $translation ) : boolean
locale ( ) : string
saveTranslations ( ) : boolean

Private Methods

Method Description
alwaysFillable ( ) : boolean
getFallbackLocale ( null $locale = null ) : string
getLanguageFromCountryBasedLocale ( $locale ) : string
getTranslationByLocaleKey ( string $key )
getTranslationsTable ( ) : string
isLocaleCountryBased ( $locale ) : boolean
useFallback ( ) : boolean | null

Method Details

__isset() public method

public __isset ( $key ) : boolean
$key
return boolean

deleteTranslations() public method

Deletes all translations for this model.
public deleteTranslations ( string | array | null $locales = null )
$locales string | array | null The locales to be deleted (array or single string) (e.g., ["en", "de"] would remove these translations).

fill() public method

public fill ( array $attributes )
$attributes array

getAttribute() public method

public getAttribute ( string $key ) : mixed
$key string
return mixed

getLocaleKey() public method

public getLocaleKey ( ) : string
return string

getLocaleSeparator() protected method

protected getLocaleSeparator ( ) : string
return string

getLocales() protected method

protected getLocales ( ) : array
return array

getNewTranslation() public method

public getNewTranslation ( string $locale ) : Model
$locale string
return Illuminate\Database\Eloquent\Model

getRelationKey() public method

public getRelationKey ( ) : string
return string

getTranslation() public method

public getTranslation ( string | null $locale = null, boolean $withFallback = null ) : Model | null
$locale string | null
$withFallback boolean
return Illuminate\Database\Eloquent\Model | null

getTranslationModelName() public method

public getTranslationModelName ( ) : string
return string

getTranslationModelNameDefault() public method

getTranslationOrNew() protected method

protected getTranslationOrNew ( string $locale ) : Model | null
$locale string
return Illuminate\Database\Eloquent\Model | null

hasTranslation() public method

public hasTranslation ( string | null $locale = null ) : boolean
$locale string | null
return boolean

isKeyALocale() protected method

protected isKeyALocale ( string $key ) : boolean
$key string
return boolean

isTranslationAttribute() public method

public isTranslationAttribute ( string $key ) : boolean
$key string
return boolean

isTranslationDirty() protected method

protected isTranslationDirty ( Model $translation ) : boolean
$translation Illuminate\Database\Eloquent\Model
return boolean

locale() protected method

protected locale ( ) : string
return string

save() public method

public save ( array $options = [] ) : boolean
$options array
return boolean

saveTranslations() protected method

protected saveTranslations ( ) : boolean
return boolean

scopeListsTranslations() public method

Example usage: Country::listsTranslations('name')->get()->toArray() Will return an array with items: [ 'id' => '1', // The id of country 'name' => 'Griechenland' // The translated name ]
public scopeListsTranslations ( Builder $query, string $translationField )
$query Illuminate\Database\Eloquent\Builder
$translationField string

scopeNotTranslatedIn() public method

public scopeNotTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$locale string
return Illuminate\Database\Eloquent\Builder | static

scopeTranslated() public method

public scopeTranslated ( Builder $query ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
return Illuminate\Database\Eloquent\Builder | static

scopeTranslatedIn() public method

public scopeTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$locale string
return Illuminate\Database\Eloquent\Builder | static

scopeWhereTranslation() public method

This scope filters results by checking the translation fields.
public scopeWhereTranslation ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$key string
$value string
$locale string
return Illuminate\Database\Eloquent\Builder | static

scopeWhereTranslationLike() public method

This scope filters results by checking the translation fields.
public scopeWhereTranslationLike ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$key string
$value string
$locale string
return Illuminate\Database\Eloquent\Builder | static

scopeWithTranslation() public method

We can use this as a shortcut to improve performance in our application.
public scopeWithTranslation ( Builder $query )
$query Illuminate\Database\Eloquent\Builder

setAttribute() public method

public setAttribute ( string $key, mixed $value )
$key string
$value mixed

toArray() public method

public toArray ( ) : array
return array

translate() public method

Alias for getTranslation().
public translate ( string | null $locale = null, boolean $withFallback = false ) : Model | null
$locale string | null
$withFallback boolean
return Illuminate\Database\Eloquent\Model | null

translateOrDefault() public method

Alias for getTranslation().
public translateOrDefault ( string $locale ) : Model | null
$locale string
return Illuminate\Database\Eloquent\Model | null

translateOrNew() public method

Alias for getTranslationOrNew().
public translateOrNew ( string $locale ) : Model | null
$locale string
return Illuminate\Database\Eloquent\Model | null

translations() public method

public translations ( ) : Illuminate\Database\Eloquent\Relations\HasMany
return Illuminate\Database\Eloquent\Relations\HasMany