| 1 |
<?php |
| 2 |
|
| 3 |
namespace ipl\Stdlib\Contract; |
| 4 |
|
| 5 |
/** |
| 6 |
* Translate messages with optional context, domain scope, and plural forms |
| 7 |
*/ |
| 8 |
interface Translator |
| 9 |
{ |
| 10 |
/** |
| 11 |
* Translate a message |
| 12 |
* |
| 13 |
* @param string $message |
| 14 |
* @param ?string $context Message context |
| 15 |
* |
| 16 |
* @return string Translated message or original message if no translation is found |
| 17 |
*/ |
| 18 |
public function translate(string $message, ?string $context = null): string; |
| 19 |
|
| 20 |
/** |
| 21 |
* Translate a message in the given domain |
| 22 |
* |
| 23 |
* If no translation is found in the specified domain, the translation is also searched for in the default domain. |
| 24 |
* |
| 25 |
* @param string $domain |
| 26 |
* @param string $message |
| 27 |
* @param ?string $context Message context |
| 28 |
* |
| 29 |
* @return string Translated message or original message if no translation is found |
| 30 |
*/ |
| 31 |
public function translateInDomain(string $domain, string $message, ?string $context = null): string; |
| 32 |
|
| 33 |
/** |
| 34 |
* Translate a plural message |
| 35 |
* |
| 36 |
* The returned message is based on the given number to decide between the singular and plural forms. |
| 37 |
* That is also the case if no translation is found. |
| 38 |
* |
| 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 |
| 43 |
* |
| 44 |
* @return string Translated message or original message if no translation is found |
| 45 |
*/ |
| 46 |
public function translatePlural(string $singular, string $plural, int $number, ?string $context = null): string; |
| 47 |
|
| 48 |
/** |
| 49 |
* Translate a plural message in the given domain |
| 50 |
* |
| 51 |
* If no translation is found in the specified domain, the translation is also searched for in the default domain. |
| 52 |
* |
| 53 |
* The returned message is based on the given number to decide between the singular and plural forms. |
| 54 |
* That is also the case if no translation is found. |
| 55 |
* |
| 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 |
| 61 |
* |
| 62 |
* @return string Translated message or original message if no translation is found |
| 63 |
*/ |
| 64 |
public function translatePluralInDomain( |
| 65 |
string $domain, |
| 66 |
string $singular, |
| 67 |
string $plural, |
| 68 |
int $number, |
| 69 |
?string $context = null |
| 70 |
): string; |
| 71 |
} |