Skip to content

Fix Translation not found when contains non-standard character #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions app/Parsers/InlineHtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ private function replaceMultibyteChars(string $text, string $placeholder = '*'):
return preg_replace('/[^\x00-\x7F]/u', $placeholder, $text);
}

private function createDocument(string $text): Document
{
// First, we need to parse the text with the multibyte characters
$document = Document::fromText($text);

// Then, we need to parse the text with multibyte characters replaced by placeholders
// because Stillat\BladeParser\Document\Document::fromText treats multibyte characters
// as indentations and spaces resulting in a miscalculated Node position
$documentWithPlaceholders = Document::fromText($this->replaceMultibyteChars($text));

// Finally, we need to update the Node positions from original text
$nodesWithPlaceholders = $documentWithPlaceholders->getNodes();

foreach ($document->getNodes() as $index => $node) {
$node->position = $nodesWithPlaceholders[$index]->position;
}

return $document;
}

public function parse(InlineHtml $node)
{
if ($node->getStartPosition() > 0) {
Expand All @@ -57,9 +77,7 @@ public function parse(InlineHtml $node)
$this->startLine = $range->start->line;
}

$this->parseBladeContent(Document::fromText(
$this->replaceMultibyteChars($node->getText())
));
$this->parseBladeContent($this->createDocument($node->getText()));

if (count($this->items)) {
$blade = new Blade;
Expand Down