Translator.php
TLDR
The Translator.php file is an interface that defines methods for translating strings in different locales.
Methods
get
This method retrieves the translation for a given key. It accepts the following parameters:
-
$key
(string): The translation key. -
$replace
(array): An array of placeholders and their corresponding values to be replaced in the translation. -
$locale
(string|null): The locale to use for the translation. If not provided, the default locale will be used.
choice
This method retrieves a translation based on an integer value. It accepts the following parameters:
-
$key
(string): The translation key. -
$number
(\Countable|int|array): The integer value or an array of integer values used to determine the translation choice. -
$replace
(array): An array of placeholders and their corresponding values to be replaced in the translation. -
$locale
(string|null): The locale to use for the translation. If not provided, the default locale will be used.
getLocale
This method returns the default locale being used.
setLocale
This method sets the default locale. It accepts the following parameter:
-
$locale
(string): The locale to set as the default.
<?php
namespace Illuminate\Contracts\Translation;
interface Translator
{
/**
* Get the translation for a given key.
*
* @param string $key
* @param array $replace
* @param string|null $locale
* @return mixed
*/
public function get($key, array $replace = [], $locale = null);
/**
* Get a translation according to an integer value.
*
* @param string $key
* @param \Countable|int|array $number
* @param array $replace
* @param string|null $locale
* @return string
*/
public function choice($key, $number, array $replace = [], $locale = null);
/**
* Get the default locale being used.
*
* @return string
*/
public function getLocale();
/**
* Set the default locale.
*
* @param string $locale
* @return void
*/
public function setLocale($locale);
}