PHP Class Potsky\LaravelLocalizationHelpers\Factory\Localization

ファイルを表示 Open project: potsky/laravel-localization-helpers Class Usage Examples

Protected Properties

Property Type Description
$messageBag Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface
$translator Potsky\LaravelLocalizationHelpers\Factory\TranslatorInterface

Public Methods

Method Description
__construct ( Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface $messageBag )
convertLemmaToFlatArray ( array $lemmas ) : array
convertLemmaToStructuredArray ( array $lemmas ) : array
deleteBackupFiles ( string $lang_folder_path, integer $days, boolean | false $dryRun = false, string $ext = 'php' ) : boolean Delete backup files
extractTranslationFromPhpFile ( string $path, array $trans_methods ) : array Extract all translations from the provided file
extractTranslationsFromFolders ( array $folders, array $trans_methods, string $php_file_extension = 'php' ) : array Extract all translations from the provided folders
findLemma ( string $lemma, array $folders, array $trans_methods, boolean | false $regex = false, boolean | false $shortOutput = false, string $ext = 'php' ) : array | false Get the list of PHP code files where a lemma is defined
fixCodeStyle ( $filePath, array $fixers, $level = null ) Fix Code Style for a file or a directory
getBackupDate ( integer $offsetDay ) : boolean | string
getBackupFiles ( string $lang_directory, string $ext = 'php' ) : array Return all lang backup files
getBackupPath ( string $file_lang_path, string $date, string $ext = 'php' ) : mixed Get the backup file path according to the current file path
getFilesWithExtension ( string $path, string $ext = 'php' ) : array Return an iterator of files with specific extension in the provided paths and subpaths
getLangPath ( $lang_folder_path = null ) : string Get the lang directory path
getMessageBag ( ) : Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface Get the current used message bag for facades essentially
getPath ( string | array $path ) : array Return an absolute path without predefined variables
getShortPath ( string $path ) : string Return an relative path to the laravel directory
isAFixer ( string $fixer ) : boolean Tell if the provided fixer is a valid fixer
isALevel ( string $level ) : boolean Tell if the provided level is a valid level
isDateOlderThanDays ( DateTime $date, integer $days ) : boolean
translate ( string $word, string $to, null $from = null ) : mixed

Private Methods

Method Description
getBackupFileDate ( string $file, string $ext = 'php' ) : DateTime | null Return the date of a backup file

Method Details

__construct() public method

public __construct ( Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface $messageBag )
$messageBag Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface A message bag or a Console object for output reports

convertLemmaToFlatArray() public method

public convertLemmaToFlatArray ( array $lemmas ) : array
$lemmas array an array of lemma eg: [ 'message.lemma.child' => string(83) "/Users/potsky/WTF/laravel-localization-helpers/tests/mock/trans.php" , ... ]
return array a flat array of lemma eg: array(1) { 'message' => array(2) { 'lemma.child' => string(83) "/Users/potsky/Work/Private/GitHub/laravel-localization-helpers/tests/mock/trans.php" ...

convertLemmaToStructuredArray() public method

public convertLemmaToStructuredArray ( array $lemmas ) : array
$lemmas array an array of lemma eg: [ 'message.lemma.child' => string(83) "/Users/potsky/WTF/laravel-localization-helpers/tests/mock/trans.php" , ... ]
return array a structured array of lemma eg: array(1) { 'message' => array(2) { 'lemma' => array(9) { 'child' => string(83) "/Users/potsky/Work/Private/GitHub/laravel-localization-helpers/tests/mock/trans.php" ...

deleteBackupFiles() public method

Delete backup files
public deleteBackupFiles ( string $lang_folder_path, integer $days, boolean | false $dryRun = false, string $ext = 'php' ) : boolean
$lang_folder_path string
$days integer
$dryRun boolean | false
$ext string
return boolean

extractTranslationFromPhpFile() public method

Remove all translations containing : - $ -> auto-generated translation cannot be supported - :: -> package translations are not taken in account
public extractTranslationFromPhpFile ( string $path, array $trans_methods ) : array
$path string the file path
$trans_methods array an array of regex to catch
return array an array dot of found translations

extractTranslationsFromFolders() public method

Extract all translations from the provided folders
public extractTranslationsFromFolders ( array $folders, array $trans_methods, string $php_file_extension = 'php' ) : array
$folders array a list of folder to search in
$trans_methods array an array of regex to catch
$php_file_extension string default is php
return array

findLemma() public method

Get the list of PHP code files where a lemma is defined
public findLemma ( string $lemma, array $folders, array $trans_methods, boolean | false $regex = false, boolean | false $shortOutput = false, string $ext = 'php' ) : array | false
$lemma string A lemma to search for or a regex to search for
$folders array An array of folder to search for lemma in
$trans_methods array An array of PHP lang functions
$regex boolean | false Is lemma a regex ?
$shortOutput boolean | false Output style for file paths
$ext string
return array | false

fixCodeStyle() public method

Fix Code Style for a file or a directory
public fixCodeStyle ( $filePath, array $fixers, $level = null )
$fixers array

getBackupDate() public method

public getBackupDate ( integer $offsetDay ) : boolean | string
$offsetDay integer the count of days to subtract to the current time
return boolean | string current date

getBackupFiles() public method

Return all lang backup files
public getBackupFiles ( string $lang_directory, string $ext = 'php' ) : array
$lang_directory string the lang directory
$ext string
return array

getBackupPath() public method

Get the backup file path according to the current file path
public getBackupPath ( string $file_lang_path, string $date, string $ext = 'php' ) : mixed
$file_lang_path string
$date string
$ext string
return mixed

getFilesWithExtension() public method

Return an iterator of files with specific extension in the provided paths and subpaths
public getFilesWithExtension ( string $path, string $ext = 'php' ) : array
$path string a source path
$ext string
return array a list of file paths

getLangPath() public method

Get the lang directory path
public getLangPath ( $lang_folder_path = null ) : string
$lang_folder_path
return string the path

getMessageBag() public method

Get the current used message bag for facades essentially
public getMessageBag ( ) : Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface
return Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface

getPath() public method

Return an absolute path without predefined variables
public getPath ( string | array $path ) : array
$path string | array the relative path
return array the absolute path

getShortPath() public method

Return an relative path to the laravel directory
public getShortPath ( string $path ) : string
$path string the absolute path
return string the relative path

isAFixer() public method

Tell if the provided fixer is a valid fixer
public isAFixer ( string $fixer ) : boolean
$fixer string
return boolean

isALevel() public method

Tell if the provided level is a valid level
public isALevel ( string $level ) : boolean
$level string
return boolean

isDateOlderThanDays() public method

public isDateOlderThanDays ( DateTime $date, integer $days ) : boolean
$date DateTime
$days integer
return boolean

translate() public method

public translate ( string $word, string $to, null $from = null ) : mixed
$word string
$to string
$from null
return mixed

Property Details

$messageBag protected_oe property

protected MessageBagInterface,Potsky\LaravelLocalizationHelpers\Factory $messageBag
return Potsky\LaravelLocalizationHelpers\Factory\MessageBagInterface

$translator protected_oe property

protected TranslatorInterface,Potsky\LaravelLocalizationHelpers\Factory $translator
return Potsky\LaravelLocalizationHelpers\Factory\TranslatorInterface