Final Class Yiisoft\Translator\Extractor\TranslationExtractor
| Inheritance | Yiisoft\Translator\Extractor\TranslationExtractor |
|---|
Extracts translator IDs from files within a given path.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | TranslationExtractor constructor. |
Yiisoft\Translator\Extractor\TranslationExtractor |
| extract() | Extract messages. | Yiisoft\Translator\Extractor\TranslationExtractor |
| getSkippedLines() | Yiisoft\Translator\Extractor\TranslationExtractor | |
| hasSkippedLines() | Yiisoft\Translator\Extractor\TranslationExtractor |
Method Details
TranslationExtractor constructor.
| public mixed __construct ( string $path, string[]|null $only = null, string[]|null $except = null ) | ||
| $path | string |
Path to start extraction at. |
| $only | string[]|null |
List of patterns that the files or directories should match. See {@see \Yiisoft\Files\PathMatcher\PathMatcher}. |
| $except | string[]|null |
List of patterns that the files or directories should not match. See {@see \Yiisoft\Files\PathMatcher\PathMatcher}. |
public function __construct(string $path, ?array $only = null, ?array $except = null)
{
if (!is_dir($path)) {
throw new RuntimeException(sprintf('Directory "%s" does not exist.', $path));
}
$this->path = $path;
if ($only !== null) {
$this->only = $only;
}
if ($except !== null) {
$this->except = $except;
}
}
Extract messages.
| public array extract ( string $defaultCategory = 'app', string|null $translatorCall = null ) | ||
| $defaultCategory | string |
Category to use if category isn't set in translation call. |
| $translatorCall | string|null |
Translation call to look for. |
| return | array |
Extracted messages. |
|---|---|---|
public function extract(string $defaultCategory = 'app', ?string $translatorCall = null): array
{
$messages = [];
$parser = new ContentParser($defaultCategory, $translatorCall);
$files = FileHelper::findFiles($this->path, [
'filter' => (new PathMatcher())
->only(...$this->only)
->except(...$this->except),
'recursive' => true,
]);
foreach ($files as $file) {
/**
* @var string $fileContent We assume that `file_get_contents` can always read the file.
*/
$fileContent = file_get_contents($file);
$messages = array_merge_recursive($messages, $parser->extract($fileContent));
if ($parser->hasSkippedLines()) {
$this->skippedLines[$file] = $parser->getSkippedLines();
}
}
return $messages;
}
| public array getSkippedLines ( ) | ||
| return | array |
Lines that were skipped during parsing. The format is:
|
|---|---|---|
public function getSkippedLines(): array
{
return $this->skippedLines;
}
| public boolean hasSkippedLines ( ) | ||
| return | boolean |
Whether there are skipped lines. |
|---|---|---|
public function hasSkippedLines(): bool
{
return !empty($this->skippedLines);
}
Signup or Login in order to comment.