diff --git a/src/Loader/StrictPoLoader.php b/src/Loader/StrictPoLoader.php index 0e0b9b2..3694a80 100644 --- a/src/Loader/StrictPoLoader.php +++ b/src/Loader/StrictPoLoader.php @@ -34,9 +34,9 @@ public function loadString(string $string, Translations $translations = null): T for ($this->newEntry(); $this->getChar() !== null; $this->newEntry()) { while ($this->readComment()); $this->readContext(); - $this->readId(); - if ($this->readPlural()) { - for ($isRequired = true; $this->readPluralTranslation($isRequired); $isRequired = false); + $this->readOriginal(); + if ($this->readPlural() && $this->readPluralTranslation(true)) { + while ($this->readPluralTranslation()); } else { $this->readTranslation(); } @@ -106,9 +106,7 @@ private function readString(string $word): bool */ private function readChar(string $char): bool { - return $this->getChar() === $char - ? !!++$this->position - : false; + return $this->getChar() === $char ? !!++$this->position : false; } /** @@ -258,11 +256,11 @@ private function readComment(): bool /** * Attempts to read an identifier */ - private function readIdentifier(string $identifier, bool $isRequired = false): ?string + private function readIdentifier(string $identifier, bool $throwIfNotFound = false): ?string { $this->readWhiteSpace(); if (!$this->readString($identifier)) { - if ($isRequired) { + if ($throwIfNotFound) { throw new Exception("Expected identifier $identifier at byte {$this->position}"); } return null; @@ -286,7 +284,7 @@ private function readContext(): bool /** * Reads the original message */ - private function readId(): void + private function readOriginal(): void { $data = $this->readIdentifier('msgid', true); $this->translation = $this->translation->withOriginal($data); @@ -321,11 +319,11 @@ private function readTranslation(): void /** * Attempts to read the pluralized translation */ - private function readPluralTranslation(bool $isRequired = false): bool + private function readPluralTranslation(bool $throwIfNotFound = false): bool { $this->readWhiteSpace(); if (!$this->readString('msgstr')) { - if ($isRequired) { + if ($throwIfNotFound) { throw new Exception("Expected indexed msgstr at byte {$this->position}"); } return false;