0 follower

Final Class Yiisoft\Translator\Extractor\ContentParser

InheritanceYiisoft\Translator\Extractor\ContentParser

Extracts translation keys from a string given.

Psalm Types

Name Value
TranslatorToken string|array{0: integer, 1: string, 2: integer}

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $defaultCategory, string|null $translator null )
$defaultCategory string

Name of the category to use when no category is specified.

$translator string|null

A string containing a method call that translates the message. If not specified, "->translate" is assumed.

                public function __construct(private string $defaultCategory, ?string $translator = null)
{
    $this->setTranslator($translator ?? $this->translatorCall);
}

            
extract() public method

public array extract ( string $content )
$content string

Code to extract translation keys from.

return array

Extracted messages.

                public function extract(string $content): array
{
    $this->skippedLines = [];
    $tokens = token_get_all($content);
    return $this->extractMessagesFromTokens($tokens);
}

            
getSkippedLines() public method

public array getSkippedLines ( )
return array

Lines that were skipped during parsing.

The format is:

return [
    'fileName' => [
        [
            int $numberOfLine,
            string $incorrectLine,
        ],
    ],
]

                public function getSkippedLines(): array
{
    return $this->skippedLines;
}

            
hasSkippedLines() public method

public boolean hasSkippedLines ( )
return boolean

Whether there are skipped lines.

                public function hasSkippedLines(): bool
{
    return !empty($this->skippedLines);
}

            
setDefaultCategory() public method

public void setDefaultCategory ( string $defaultCategory )
$defaultCategory string

Name of the category to use when no category is specified.

                public function setDefaultCategory(string $defaultCategory): void
{
    $this->defaultCategory = $defaultCategory;
}