Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict Translator interface #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
42 changes: 24 additions & 18 deletions src/Contract/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ interface Translator
/**
* Translate a message
*
* @param string $message
* @param string $context Message context
* @param string $message
* @param ?string $context Message context
*
* @return string Translated message or original message if no translation is found
*/
public function translate($message, $context = null);
public function translate(string $message, ?string $context = null): string;

/**
* Translate a message in the given domain
*
* If no translation is found in the specified domain, the translation is also searched for in the default domain.
*
* @param string $domain
* @param string $message
* @param string $context Message context
* @param string $domain
* @param string $message
* @param ?string $context Message context
*
* @return string Translated message or original message if no translation is found
*/
public function translateInDomain($domain, $message, $context = null);
public function translateInDomain(string $domain, string $message, ?string $context = null): string;

/**
* Translate a plural message
*
* The returned message is based on the given number to decide between the singular and plural forms.
* That is also the case if no translation is found.
*
* @param string $singular Singular message
* @param string $plural Plural message
* @param int $number Number to decide between the returned singular and plural forms
* @param string $context Message context
* @param string $singular Singular message
* @param string $plural Plural message
* @param int $number Number to decide between the returned singular and plural forms
* @param ?string $context Message context
*
* @return string Translated message or original message if no translation is found
*/
public function translatePlural($singular, $plural, $number, $context = null);
public function translatePlural(string $singular, string $plural, int $number, ?string $context = null): string;

/**
* Translate a plural message in the given domain
Expand All @@ -53,13 +53,19 @@ public function translatePlural($singular, $plural, $number, $context = null);
* The returned message is based on the given number to decide between the singular and plural forms.
* That is also the case if no translation is found.
*
* @param string $domain
* @param string $singular Singular message
* @param string $plural Plural message
* @param int $number Number to decide between the returned singular and plural forms
* @param string $context Message context
* @param string $domain
* @param string $singular Singular message
* @param string $plural Plural message
* @param int $number Number to decide between the returned singular and plural forms
* @param ?string $context Message context
*
* @return string Translated message or original message if no translation is found
*/
public function translatePluralInDomain($domain, $singular, $plural, $number, $context = null);
public function translatePluralInDomain(
string $domain,
string $singular,
string $plural,
int $number,
?string $context = null
): string;
}