trait Localization

Trait Localization.

Embed default and locale translators and translation base methods.

Properties

staticprotectedTranslatorInterface $translator Default translator.
protectedTranslatorInterface $localTranslator Specific translator of the current instance.
staticprotectedint $humanDiffOptions Options for diffForHumans().

Methods

static 
setHumanDiffOptions(int$humanDiffOptions)deprecated

No description

static 
enableHumanDiffOption(int$humanDiffOption)deprecated

No description

static 
disableHumanDiffOption(int$humanDiffOption)deprecated

No description

static int
getHumanDiffOptions()

Return default humanDiff() options (merged flags as integer).

static TranslatorInterface
getTranslator()

Get the default translator instance in use.

static void
setTranslator(TranslatorInterface$translator)

Set the default translator instance to use.

bool
hasLocalTranslator()

Return true if the current instance has its own translator.

TranslatorInterface
getLocalTranslator()

Get the translator of the current instance or the default if none set.

$this
setLocalTranslator(TranslatorInterface$translator)

Set the translator for the current instance.

static string
getTranslationMessageWith(TranslatorInterface$translator,string$key,string|null$locale =null,string|null$default =null)

Returns raw translation message for a given key.

string
getTranslationMessage(string$key,string|null$locale =null,string|null$default =null,TranslatorInterface$translator =null)

Returns raw translation message for a given key.

static string
translateWith(TranslatorInterface$translator,string$key,array$parameters =[],null$number =null)

Translate using translation string or callback available.

string
translate(string$key,array$parameters =[],string|int|float|null$number =null,TranslatorInterface|null$translator =null,bool$altNumbers =false)

Translate using translation string or callback available.

string
translateNumber(int$number)

Returns the alternative number for a given integer if available in the current locale.

static string
translateTimeString(string$timeString,string|null$from =null,string|null$to =null,int$mode =CarbonInterface::TRANSLATE_ALL)

Translate a time string from a locale to an other.

string
translateTimeStringTo(string$timeString,string|null$to =null)

Translate a time string from the current locale ($date->locale()) to an other.

$this|string
locale(string$locale =null,string...$fallbackLocales)

Get/set the locale for the current instance.

static string
getLocale()

Get the current translator locale.

static bool
setLocale(string$locale)

Set the current translator locale and indicate if the source locale file exists.

static 
setFallbackLocale(string$locale)

Set the fallback locale.

static string|null
getFallbackLocale()

Get the fallback locale.

static mixed
executeWithLocale(string$locale,callable$func)

Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).

static bool
localeHasShortUnits(string$locale)

Returns true if the given locale is internally supported and has short-units support.

static bool
localeHasDiffSyntax(string$locale)

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).

static bool
localeHasDiffOneDayWords(string$locale)

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).

static bool
localeHasDiffTwoDayWords(string$locale)

Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).

static bool
localeHasPeriodSyntax(string$locale)

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).

static array
getAvailableLocales()

Returns the list of internally available locales and already loaded custom locales.

static Language[]
getAvailableLocalesInfo()

Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.

static TranslatorInterface
translator()

Initialize the default translator instance if necessary.

string|null
getTranslatorLocale(null$translator =null)

Get the locale of a given translator.

static LocaleAwareInterface|null
getLocaleAwareTranslator(LocaleAwareInterface|null$translator =null)

Throw an error if passed object is not LocaleAwareInterface.

Details

at line70
static setHumanDiffOptions(int$humanDiffOptions)deprecated

deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

Parameters

int $humanDiffOptions

See also

settings

at line82
static enableHumanDiffOption(int$humanDiffOption)deprecated

deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

Parameters

int $humanDiffOption

See also

settings

at line94
static disableHumanDiffOption(int$humanDiffOption)deprecated

deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.

Parameters

int $humanDiffOption

See also

settings

at line104
staticint getHumanDiffOptions()

Return default humanDiff() options (merged flags as integer).

Return Value

int

at line114
staticTranslatorInterface getTranslator()

Get the default translator instance in use.

Return Value

TranslatorInterface

at line126
staticvoid setTranslator(TranslatorInterface$translator)

Set the default translator instance to use.

Parameters

TranslatorInterface $translator

Return Value

void

at line136
bool hasLocalTranslator()

Return true if the current instance has its own translator.

Return Value

bool

at line146
TranslatorInterface getLocalTranslator()

Get the translator of the current instance or the default if none set.

Return Value

TranslatorInterface

at line158
$this setLocalTranslator(TranslatorInterface$translator)

Set the translator for the current instance.

Parameters

TranslatorInterface $translator

Return Value

$this

at line175
staticstring getTranslationMessageWith(TranslatorInterface$translator,string$key,string|null$locale =null,string|null$default =null)

Returns raw translation message for a given key.

Parameters

TranslatorInterface $translator the translator to use
string $key key to find
string|null $locale current locale used if null
string|null $default default value if translation returns the key

Return Value

string

at line203
string getTranslationMessage(string$key,string|null$locale =null,string|null$default =null,TranslatorInterface$translator =null)

Returns raw translation message for a given key.

Parameters

string $key key to find
string|null $locale current locale used if null
string|null $default default value if translation returns the key
TranslatorInterface $translator an optional translator to use

Return Value

string

at line218
staticstring translateWith(TranslatorInterface$translator,string$key,array$parameters =[],null$number =null)

Translate using translation string or callback available.

Parameters

TranslatorInterface $translator
string $key
array $parameters
null $number

Return Value

string

at line252
string translate(string$key,array$parameters =[],string|int|float|null$number =null,TranslatorInterface|null$translator =null,bool$altNumbers =false)

Translate using translation string or callback available.

Parameters

string $key
array $parameters
string|int|float|null $number
TranslatorInterface|null $translator
bool $altNumbers

Return Value

string

at line270
string translateNumber(int$number)

Returns the alternative number for a given integer if available in the current locale.

Parameters

int $number

Return Value

string

at line329
staticstring translateTimeString(string$timeString,string|null$from =null,string|null$to =null,int$mode =CarbonInterface::TRANSLATE_ALL)

Translate a time string from a locale to an other.

Parameters

string $timeString date/time/duration string to translate (may also contain English)
string|null $from input locale of the $timeString parameter (Carbon::getLocale() by default)
string|null $to output locale of the result returned ("en" by default)
int $mode specify what to translate with options: - CarbonInterface::TRANSLATE_ALL (default) - CarbonInterface::TRANSLATE_MONTHS - CarbonInterface::TRANSLATE_DAYS - CarbonInterface::TRANSLATE_UNITS - CarbonInterface::TRANSLATE_MERIDIEM You can use pipe to group: CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS

Return Value

string

at line425
string translateTimeStringTo(string$timeString,string|null$to =null)

Translate a time string from the current locale ($date->locale()) to an other.

Parameters

string $timeString time string to translate
string|null $to output locale of the result returned ("en" by default)

Return Value

string

at line438
$this|string locale(string$locale =null,string...$fallbackLocales)

Get/set the locale for the current instance.

Parameters

string $locale
string ...$fallbackLocales

Return Value

$this|string

at line470
staticstring getLocale()

Get the current translator locale.

Return Value

string

at line483
staticbool setLocale(string$locale)

Set the current translator locale and indicate if the source locale file exists.

Pass 'auto' as locale to use closest language from the current LC_TIME locale.

Parameters

string $locale locale ex. en

Return Value

bool

at line495
static setFallbackLocale(string$locale)

Set the fallback locale.

at line520
staticstring|null getFallbackLocale()

Get the fallback locale.

at line540
staticmixed executeWithLocale(string$locale,callable$func)

Set the current locale to the given, execute the passed function, reset the locale to previous one, then return the result of the closure (or null if the closure was void).

Parameters

string $locale locale ex. en
callable $func

Return Value

mixed

at line557
staticbool localeHasShortUnits(string$locale)

Returns true if the given locale is internally supported and has short-units support.

Support is considered enabled if either year, day or hour has a short variant translated.

Parameters

string $locale locale ex. en

Return Value

bool

at line578
staticbool localeHasDiffSyntax(string$locale)

Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).

Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters

string $locale locale ex. en

Return Value

bool

at line609
staticbool localeHasDiffOneDayWords(string$locale)

Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).

Support is considered enabled if the 3 words are translated in the given locale.

Parameters

string $locale locale ex. en

Return Value

bool

at line627
staticbool localeHasDiffTwoDayWords(string$locale)

Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).

Support is considered enabled if the 2 words are translated in the given locale.

Parameters

string $locale locale ex. en

Return Value

bool

at line644
staticbool localeHasPeriodSyntax(string$locale)

Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).

Support is considered enabled if the 4 sentences are translated in the given locale.

Parameters

string $locale locale ex. en

Return Value

bool

at line661
staticarray getAvailableLocales()

Returns the list of internally available locales and already loaded custom locales.

(It will ignore custom translator dynamic loading.)

Return Value

array

at line676
staticLanguage[] getAvailableLocalesInfo()

Returns list of Language object for each available locale. This object allow you to get the ISO name, native name, region and variant of the locale.

Return Value

Language[]

at line691
staticprotectedTranslatorInterface translator()

Initialize the default translator instance if necessary.

Return Value

TranslatorInterface

at line710
protectedstring|null getTranslatorLocale(null$translator =null)

Get the locale of a given translator.

If null or omitted, current local translator is used. If no local translator is in use, current global translator is used.

Parameters

null $translator

Return Value

string|null

at line728
staticprotectedLocaleAwareInterface|null getLocaleAwareTranslator(LocaleAwareInterface|null$translator =null)

Throw an error if passed object is not LocaleAwareInterface.

Parameters

LocaleAwareInterface|null $translator

Return Value

LocaleAwareInterface|null