Skip to content

Commit

Permalink
Merge #38 - Fix #37 - Translator::selectString() must be of the type …
Browse files Browse the repository at this point in the history
…integer, boolean returned

Pull-request: #38
Fixes: #37

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Nov 20, 2020
2 parents c39d601 + dc07d38 commit 8d68daf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ private function selectString(int $n): int
$this->getPluralForms(),
['n' => $n]
);
if ($plural === false) {
$plural = 0;
}
} catch (Throwable $e) {
$plural = 0;
}
Expand Down
34 changes: 34 additions & 0 deletions tests/PluralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,38 @@ public function testNgettext(): void
);
$this->assertSame('', $result);
}

/**
* Test for ngettext
*
* @see https://github.com/phpmyadmin/motranslator/issues/37
*/
public function testNgettextSelectString(): void
{
$parser = new Translator('');
$parser->setTranslation(
'',
"Project-Id-Version: phpMyAdmin 5.1.0-dev\n"
. "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n"
. "PO-Revision-Date: 2020-09-01 09:12+0000\n"
. "Last-Translator: William Desportes <williamdes@wdes.fr>\n"
. 'Language-Team: English (United Kingdom) '
. "<https:\/\/hosted.weblate.org\/projects\/phpmyadmin\/master\/en_GB\/>\n"
. "Language: en_GB\n"
. "MIME-Version: 1.0\n"
. "Content-Type: text\/plain; charset=UTF-8\n"
. "Content-Transfer-Encoding: 8bit\n"
. "Plural-Forms: nplurals=2; plural=n != 1;\n"
. "X-Generator: Weblate 4.2.1-dev\n"
. ''
);
$translationKey = implode(chr(0), ["%d pig went to the market\n", "%d pigs went to the market\n"]);
$parser->setTranslation($translationKey, 'ok');
$result = $parser->ngettext(
"%d pig went to the market\n",
"%d pigs went to the market\n",
1
);
$this->assertSame('ok', $result);
}
}

0 comments on commit 8d68daf

Please sign in to comment.