Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions src/Translator.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

declare(strict_types=1);
Expand Down Expand Up @@ -133,10 +133,18 @@
/**
* Check if a string is translated.
*
* @param string $msgid String to be checked
* A string with plural forms is stored under its singular and plural msgids
* together, so pass the plural msgid as well to check it, as for ngettext().
*
* @param string $msgid String to be checked
* @param string|null $msgidPlural Plural form of the string, if it has one
*/
public function exists(string $msgid): bool
public function exists(string $msgid, string|null $msgidPlural = null): bool
{
if ($msgidPlural !== null) {
$msgid .= "\u{0}" . $msgidPlural;
}

return $this->cache->has($msgid);
}

Expand Down
9 changes: 9 additions & 0 deletions tests/MoFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ public function testExists(string $file): void
self::assertFalse($parser->exists('Column parser'));
}

#[DataProvider('provideMoFiles')]
public function testExistsWithPlural(string $file): void
{
$parser = $this->getTranslator($file);
self::assertTrue($parser->exists('%d second', '%d seconds'));
self::assertFalse($parser->exists('%d second', '%d minutes'));
self::assertFalse($parser->exists('%d second'));
}

/**
* @param string $pattern path names pattern to match
*
Expand Down
Loading