PHP Class Waavi\Translation\Repositories\TranslationRepository

Inheritance: extends Waavi\Translation\Repositories\Repository
显示文件 Open project: waavi/translation Class Usage Examples

Protected Properties

Property Type Description
$database Illuminate\Database\Connection
$errors Illuminate\Support\MessageBag @var \Illuminate\Support\MessageBag
$model Waavi\Translation\Models\Translation The model being queried.
$validator Illuminate\Validation\Validator @var \Illuminate\Validation\Validator

Public Methods

Method Description
__construct ( Waavi\Translation\Models\Translation $model, Illuminate\Foundation\Application $app ) : void Constructor
allByLocale ( string $locale, $perPage ) : Waavi\Translation\Models\Translation Return a list of translations for the given language. If perPage is > 0 a paginated list is returned with perPage items per page.
create ( array $attributes ) : boolean Insert a new translation into the database.
delete ( integer $id ) : boolean Delete a translation. If the translation is of the default language, delete all translations with the same namespace, group and item
deleteByCode ( string $code ) : boolean Delete all entries by code
findByCode ( string $locale, string $namespace, string $group, string $item ) : Waavi\Translation\Models\Translation Find a translation per namespace, group and item values
findByLangCode ( string $locale, $code ) : Waavi\Translation\Models\Translation Find a translation per namespace, group and item values
flagAsReviewed ( integer $id ) : boolean Flag the entry with the given id as reviewed.
flagAsUnstable ( $namespace, $group, $item ) : boolean Flag all entries with the given namespace, group and item and locale other than default as pending review.
getItems ( string $locale, string $namespace, string $group ) : array Return all items for a given locale, namespace and group
loadArray ( array $lines, string $locale, string $group, string $namespace = '*' ) : void Loads a localization array from a localization file into the databas.
loadSource ( string $locale, string $namespace, string $group ) : array Return all items formatted as if coming from a PHP language file.
parseCode ( string $code ) : boolean Parse a translation code into its components
pendingReview ( string $locale, integer $perPage ) : Waavi\Translation\Models\Translation Retrieve translations pending review for the given locale.
randomUntranslated ( string $locale ) : Waavi\Translation\Models\Translation Find a random entry that is present in the default locale but not in the given one.
search ( string $locale, string $partialCode, integer $perPage ) : Waavi\Translation\Models\Translation Search for entries given a partial code and a locale
translateText ( string $text, string $textLocale, string $targetLocale ) : array Check if there are existing translations for the given text in the given locale for the target locale.
untranslated ( string $locale, integer $perPage, string $text = null ) : Collection List all entries in the default locale that do not exist for the target locale.
update ( $id, $text ) : boolean Update a translation.
updateAndLock ( $id, $text ) : boolean Update and lock translation. Locked translations will not be ovewritten when loading translation files into the database.
updateDefaultByCode ( string $code, string $text ) : boolean Insert or Update entry by translation code for the default locale.
validate ( array $attributes ) : boolean Validate the given attributes
validationErrors ( ) : Illuminate\Support\MessageBag Returns the validations errors of the last action executed.

Protected Methods

Method Description
untranslatedQuery ( string $locale ) : Builder Create and return a new query to identify untranslated records.

Method Details

__construct() public method

@param \Waavi\Translation\Models\Translation $model Bade model for queries.
public __construct ( Waavi\Translation\Models\Translation $model, Illuminate\Foundation\Application $app ) : void
$model Waavi\Translation\Models\Translation
$app Illuminate\Foundation\Application
return void

allByLocale() public method

@param string $locale
public allByLocale ( string $locale, $perPage ) : Waavi\Translation\Models\Translation
$locale string
return Waavi\Translation\Models\Translation

create() public method

If the attributes are not valid, a null response is given and the errors can be retrieved through validationErrors()
public create ( array $attributes ) : boolean
$attributes array Model attributes @return boolean
return boolean

delete() public method

@param integer $id
public delete ( integer $id ) : boolean
$id integer
return boolean

deleteByCode() public method

@param string $code
public deleteByCode ( string $code ) : boolean
$code string
return boolean

findByCode() public method

@param string $locale
public findByCode ( string $locale, string $namespace, string $group, string $item ) : Waavi\Translation\Models\Translation
$locale string
$namespace string @param string $group @param string $item @return Translation
$group string
$item string
return Waavi\Translation\Models\Translation

findByLangCode() public method

@param string $locale
public findByLangCode ( string $locale, $code ) : Waavi\Translation\Models\Translation
$locale string
return Waavi\Translation\Models\Translation

flagAsReviewed() public method

@param integer $id
public flagAsReviewed ( integer $id ) : boolean
$id integer
return boolean

flagAsUnstable() public method

This is used when an entry for the default locale is updated.
public flagAsUnstable ( $namespace, $group, $item ) : boolean
return boolean

getItems() public method

@param string $locale
public getItems ( string $locale, string $namespace, string $group ) : array
$locale string
$namespace string @param string $group @return array
$group string
return array

loadArray() public method

@param array $lines
public loadArray ( array $lines, string $locale, string $group, string $namespace = '*' ) : void
$lines array
$locale string @param string $group @param string $namespace @return void
$group string
$namespace string
return void

loadSource() public method

@param string $locale
public loadSource ( string $locale, string $namespace, string $group ) : array
$locale string
$namespace string @param string $group @return array
$group string
return array

parseCode() public method

@param string $code
public parseCode ( string $code ) : boolean
$code string
return boolean

pendingReview() public method

@param string $locale
public pendingReview ( string $locale, integer $perPage ) : Waavi\Translation\Models\Translation
$locale string
$perPage integer Number of elements per page. 0 if all are wanted. @return Translation
return Waavi\Translation\Models\Translation

randomUntranslated() public method

@param string $locale Locale to translate to.
public randomUntranslated ( string $locale ) : Waavi\Translation\Models\Translation
$locale string
return Waavi\Translation\Models\Translation

translateText() public method

@param string $text
public translateText ( string $text, string $textLocale, string $targetLocale ) : array
$text string
$textLocale string @param string $targetLocale @return array
$targetLocale string
return array

untranslated() public method

@param string $locale Language to translate to.
public untranslated ( string $locale, integer $perPage, string $text = null ) : Collection
$locale string
$perPage integer If greater than zero, return a paginated list with $perPage items per page. @param string $text [optional] Show only entries with the given text in them in the reference language. @return Collection
$text string
return Collection

untranslatedQuery() protected method

Create and return a new query to identify untranslated records.
protected untranslatedQuery ( string $locale ) : Builder
$locale string
return Illuminate\Database\Query\Builder

update() public method

If the translation is locked, no update will be made.
public update ( $id, $text ) : boolean
return boolean

updateAndLock() public method

This will force and update if the translation is locked. If the attributes are not valid, a null response is given and the errors can be retrieved through validationErrors()
public updateAndLock ( $id, $text ) : boolean
return boolean

updateDefaultByCode() public method

@param string $code
public updateDefaultByCode ( string $code, string $text ) : boolean
$code string
$text string @return boolean
return boolean

validate() public method

@param array $attributes
public validate ( array $attributes ) : boolean
$attributes array
return boolean

validationErrors() public method

@return \Illuminate\Support\MessageBag
public validationErrors ( ) : Illuminate\Support\MessageBag
return Illuminate\Support\MessageBag

Property Details

$database protected_oe property

protected Connection,Illuminate\Database $database
return Illuminate\Database\Connection

$errors protected_oe property

@var \Illuminate\Support\MessageBag
protected MessageBag,Illuminate\Support $errors
return Illuminate\Support\MessageBag

$model protected_oe property

The model being queried.
protected Translation,Waavi\Translation\Models $model
return Waavi\Translation\Models\Translation

$validator protected_oe property

@var \Illuminate\Validation\Validator
protected Validator,Illuminate\Validation $validator
return Illuminate\Validation\Validator