Skip to content

Commit

Permalink
php-gettext#282 Renamed identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Jul 20, 2022
1 parent 8439ddb commit faeef90
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Loader/StrictPoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit faeef90

Please sign in to comment.