PHP Class Themsaid\Langman\Manager

Exibir arquivo Open project: themsaid/laravel-langman Class Usage Examples

Public Methods

Method Description
__construct ( Illuminate\Filesystem\Filesystem $disk, string $path, array $syncPaths ) Manager constructor.
collectFromFiles ( ) : array Collect all translation keys from views files.
createFile ( $fileName ) : void Create a file for all languages if does not exist already.
files ( ) : array Array of language files grouped by file name.
fillKeys ( string $fileName, array $keys ) : void Fills translation lines for given keys in different languages.
getAllViewFilesWithTranslations ( ) : array Get found translation lines found per file.
getFileContent ( string $filePath, boolean $createIfNotExists = false ) : array Get the content in the given file path.
getKeysExistingInALanguageButNotTheOther ( $values ) : array Extract keys that exists in a language but not the other.
languages ( ) : array Array of supported languages.
removeKey ( string $fileName, string $key ) : void Remove a key from all language files.
setPathToVendorPackage ( string $packageName ) : void Sets the path to a vendor package translation files.
writeFile ( string $filePath, array $translations ) : void Write a language file from array.

Private Methods

Method Description
neglectVendorFiles ( $filesByFile ) : array Nelgect all vendor files.
stringLineMaker ( $array, $prepend = '' ) : string Write the lines of the inner array of the language file.

Method Details

__construct() public method

Manager constructor.
public __construct ( Illuminate\Filesystem\Filesystem $disk, string $path, array $syncPaths )
$disk Illuminate\Filesystem\Filesystem
$path string
$syncPaths array

collectFromFiles() public method

e.g. ['users' => ['city', 'name', 'phone']]
public collectFromFiles ( ) : array
return array

createFile() public method

Create a file for all languages if does not exist already.
public createFile ( $fileName ) : void
$fileName
return void

files() public method

ex: ['user' => ['en' => 'user.php', 'nl' => 'user.php']]
public files ( ) : array
return array

fillKeys() public method

ex. for $keys = ['name' => ['en' => 'name', 'nl' => 'naam']
public fillKeys ( string $fileName, array $keys ) : void
$fileName string
$keys array
return void

getAllViewFilesWithTranslations() public method

e.g. ['users.blade.php' => ['users.name'], 'users/index.blade.php' => ['users.phone', 'users.city']]

getFileContent() public method

Get the content in the given file path.
public getFileContent ( string $filePath, boolean $createIfNotExists = false ) : array
$filePath string
$createIfNotExists boolean
return array

getKeysExistingInALanguageButNotTheOther() public method

Given a dot array of all keys in the format 'file.language.key', this method searches for keys that exist in one language but not the other and outputs an array consists of those keys.
public getKeysExistingInALanguageButNotTheOther ( $values ) : array
$values
return array

languages() public method

ex: ['en', 'sp']
public languages ( ) : array
return array

removeKey() public method

Remove a key from all language files.
public removeKey ( string $fileName, string $key ) : void
$fileName string
$key string
return void

setPathToVendorPackage() public method

Sets the path to a vendor package translation files.
public setPathToVendorPackage ( string $packageName ) : void
$packageName string
return void

writeFile() public method

Write a language file from array.
public writeFile ( string $filePath, array $translations ) : void
$filePath string
$translations array
return void