Skip to content

Commit 3fdfa0e

Browse files
committed
Translator: Use a more strict interface
1 parent 8bd5759 commit 3fdfa0e

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/Contract/Translator.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,40 @@ interface Translator
1010
/**
1111
* Translate a message
1212
*
13-
* @param string $message
14-
* @param string $context Message context
13+
* @param string $message
14+
* @param ?string $context Message context
1515
*
1616
* @return string Translated message or original message if no translation is found
1717
*/
18-
public function translate($message, $context = null);
18+
public function translate(string $message, ?string $context = null): string;
1919

2020
/**
2121
* Translate a message in the given domain
2222
*
2323
* If no translation is found in the specified domain, the translation is also searched for in the default domain.
2424
*
25-
* @param string $domain
26-
* @param string $message
27-
* @param string $context Message context
25+
* @param string $domain
26+
* @param string $message
27+
* @param ?string $context Message context
2828
*
2929
* @return string Translated message or original message if no translation is found
3030
*/
31-
public function translateInDomain($domain, $message, $context = null);
31+
public function translateInDomain(string $domain, string $message, ?string $context = null): string;
3232

3333
/**
3434
* Translate a plural message
3535
*
3636
* The returned message is based on the given number to decide between the singular and plural forms.
3737
* That is also the case if no translation is found.
3838
*
39-
* @param string $singular Singular message
40-
* @param string $plural Plural message
41-
* @param int $number Number to decide between the returned singular and plural forms
42-
* @param string $context Message context
39+
* @param string $singular Singular message
40+
* @param string $plural Plural message
41+
* @param int $number Number to decide between the returned singular and plural forms
42+
* @param ?string $context Message context
4343
*
4444
* @return string Translated message or original message if no translation is found
4545
*/
46-
public function translatePlural($singular, $plural, $number, $context = null);
46+
public function translatePlural(string $singular, string $plural, int $number, ?string $context = null): string;
4747

4848
/**
4949
* Translate a plural message in the given domain
@@ -53,13 +53,19 @@ public function translatePlural($singular, $plural, $number, $context = null);
5353
* The returned message is based on the given number to decide between the singular and plural forms.
5454
* That is also the case if no translation is found.
5555
*
56-
* @param string $domain
57-
* @param string $singular Singular message
58-
* @param string $plural Plural message
59-
* @param int $number Number to decide between the returned singular and plural forms
60-
* @param string $context Message context
56+
* @param string $domain
57+
* @param string $singular Singular message
58+
* @param string $plural Plural message
59+
* @param int $number Number to decide between the returned singular and plural forms
60+
* @param ?string $context Message context
6161
*
6262
* @return string Translated message or original message if no translation is found
6363
*/
64-
public function translatePluralInDomain($domain, $singular, $plural, $number, $context = null);
64+
public function translatePluralInDomain(
65+
string $domain,
66+
string $singular,
67+
string $plural,
68+
int $number,
69+
?string $context = null
70+
): string;
6571
}

0 commit comments

Comments
 (0)