Skip to content

Commit a5d07c8

Browse files
Jan-Schuppiklippserd
authored andcommitted
Translator: Add strict type declarations
This change requires adjustments to the following consumers: ipl-i18n - src/GettextTranslator.php - src/NoopTranslator.php PHPDoc adjusted: nullable shorthand, union type ordering, compact format.
1 parent 8322a77 commit a5d07c8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/Contract/Translator.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ interface Translator
1111
* Translate a message
1212
*
1313
* @param string $message
14-
* @param string $context Message context
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
@@ -24,11 +24,11 @@ public function translate($message, $context = null);
2424
*
2525
* @param string $domain
2626
* @param string $message
27-
* @param string $context Message context
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
@@ -37,13 +37,13 @@ public function translateInDomain($domain, $message, $context = null);
3737
* That is also the case if no translation is found.
3838
*
3939
* @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
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
@@ -55,11 +55,17 @@ public function translatePlural($singular, $plural, $number, $context = null);
5555
*
5656
* @param string $domain
5757
* @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
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)