FileAccess Orion

Localization

Trait Localization.

Embed default and locale translators and translation base methods.

Table of Contents

$humanDiffOptions  : int
Options for diffForHumans().
$localTranslator  : TranslatorInterface
Specific translator of the current instance.
$translator  : TranslatorInterface
Default translator.
disableHumanDiffOption()  : mixed
enableHumanDiffOption()  : mixed
executeWithLocale()  : mixed
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).
getAvailableLocales()  : array<string|int, mixed>
Returns the list of internally available locales and already loaded custom locales.
getAvailableLocalesInfo()  : array<string|int, Language>
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.
getFallbackLocale()  : string|null
Get the fallback locale.
getHumanDiffOptions()  : int
Return default humanDiff() options (merged flags as integer).
getLocale()  : string
Get the current translator locale.
getLocalTranslator()  : TranslatorInterface
Get the translator of the current instance or the default if none set.
getTranslationMessage()  : string
Returns raw translation message for a given key.
getTranslationMessageWith()  : string
Returns raw translation message for a given key.
getTranslator()  : TranslatorInterface
Get the default translator instance in use.
hasLocalTranslator()  : bool
Return true if the current instance has its own translator.
locale()  : $this|string
Get/set the locale for the current instance.
localeHasDiffOneDayWords()  : bool
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
localeHasDiffSyntax()  : bool
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
localeHasDiffTwoDayWords()  : bool
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
localeHasPeriodSyntax()  : bool
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
localeHasShortUnits()  : bool
Returns true if the given locale is internally supported and has short-units support.
setFallbackLocale()  : mixed
Set the fallback locale.
setHumanDiffOptions()  : mixed
setLocale()  : bool
Set the current translator locale and indicate if the source locale file exists.
setLocalTranslator()  : $this
Set the translator for the current instance.
setTranslator()  : void
Set the default translator instance to use.
translate()  : string
Translate using translation string or callback available.
translateNumber()  : string
Returns the alternative number for a given integer if available in the current locale.
translateTimeString()  : string
Translate a time string from a locale to an other.
translateTimeStringTo()  : string
Translate a time string from the current locale (`$date->locale()`) to an other.
translateWith()  : string
Translate using translation string or callback available.
getLocaleAwareTranslator()  : LocaleAwareInterface|null
Throw an error if passed object is not LocaleAwareInterface.
getTranslatorLocale()  : string|null
translator()  : TranslatorInterface
Initialize the default translator instance if necessary.
getTranslationArray()  : mixed

Properties

$humanDiffOptions

Options for diffForHumans().

protected static int $humanDiffOptions = \Carbon\CarbonInterface::NO_ZERO_DIFF

Methods

disableHumanDiffOption()

public static disableHumanDiffOption(int $humanDiffOption) : mixed
Parameters
$humanDiffOption : int
Tags
deprecated

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

see
settings
Return values
mixed

enableHumanDiffOption()

public static enableHumanDiffOption(int $humanDiffOption) : mixed
Parameters
$humanDiffOption : int
Tags
deprecated

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

see
settings
Return values
mixed

executeWithLocale()

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).

public static executeWithLocale(string $locale, callable $func) : mixed
Parameters
$locale : string

locale ex. en

$func : callable
Return values
mixed

getAvailableLocales()

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

public static getAvailableLocales() : array<string|int, mixed>

(It will ignore custom translator dynamic loading.)

Return values
array<string|int, mixed>

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.

public static getAvailableLocalesInfo() : array<string|int, Language>
Return values
array<string|int, Language>

getHumanDiffOptions()

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

public static getHumanDiffOptions() : int
Return values
int

getLocale()

Get the current translator locale.

public static getLocale() : string
Return values
string

getTranslationMessage()

Returns raw translation message for a given key.

public getTranslationMessage(string $key[, string|null $locale = null ][, string|null $default = null ][, TranslatorInterface $translator = null ]) : string
Parameters
$key : string

key to find

$locale : string|null = null

current locale used if null

$default : string|null = null

default value if translation returns the key

$translator : TranslatorInterface = null

an optional translator to use

Return values
string

getTranslationMessageWith()

Returns raw translation message for a given key.

public static getTranslationMessageWith(TranslatorInterface $translator, string $key[, string|null $locale = null ][, string|null $default = null ]) : string
Parameters
$translator : TranslatorInterface

the translator to use

$key : string

key to find

$locale : string|null = null

current locale used if null

$default : string|null = null

default value if translation returns the key

Return values
string

hasLocalTranslator()

Return true if the current instance has its own translator.

public hasLocalTranslator() : bool
Return values
bool

locale()

Get/set the locale for the current instance.

public locale([string|null $locale = null ], array<string|int, string> ...$fallbackLocales) : $this|string
Parameters
$locale : string|null = null
$fallbackLocales : array<string|int, string>
Return values
$this|string

localeHasDiffOneDayWords()

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

public static localeHasDiffOneDayWords(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasDiffSyntax()

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

public static localeHasDiffSyntax(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasDiffTwoDayWords()

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

public static localeHasDiffTwoDayWords(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasPeriodSyntax()

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

public static localeHasPeriodSyntax(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

localeHasShortUnits()

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

public static localeHasShortUnits(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

setHumanDiffOptions()

public static setHumanDiffOptions(int $humanDiffOptions) : mixed
Parameters
$humanDiffOptions : int
Tags
deprecated

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

see
settings
Return values
mixed

setLocale()

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

public static setLocale(string $locale) : bool

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

Parameters
$locale : string

locale ex. en

Return values
bool

translate()

Translate using translation string or callback available.

public translate(string $key[, array<string|int, mixed> $parameters = [] ][, null $number = null ][, TranslatorInterface $translator = null ][, bool $altNumbers = false ]) : string
Parameters
$key : string
$parameters : array<string|int, mixed> = []
$number : null = null
$translator : TranslatorInterface = null
$altNumbers : bool = false
Return values
string

translateNumber()

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

public translateNumber(int $number) : string
Parameters
$number : int
Return values
string

translateTimeString()

Translate a time string from a locale to an other.

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

time string to translate

$from : string|null = null

input locale of the $timeString parameter (Carbon::getLocale() by default)

$to : string|null = null

output locale of the result returned ("en" by default)

$mode : int = CarbonInterface::TRANSLATE_ALL

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 values
string

translateTimeStringTo()

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

public translateTimeStringTo(string $timeString[, string|null $to = null ]) : string
Parameters
$timeString : string

time string to translate

$to : string|null = null

output locale of the result returned ("en" by default)

Return values
string

translateWith()

Translate using translation string or callback available.

public static translateWith(TranslatorInterface $translator, string $key[, array<string|int, mixed> $parameters = [] ][, null $number = null ]) : string
Parameters
$translator : TranslatorInterface
$key : string
$parameters : array<string|int, mixed> = []
$number : null = null
Return values
string

getTranslatorLocale()

protected getTranslatorLocale([mixed $translator = null ]) : string|null
Parameters
$translator : mixed = null
Return values
string|null

getTranslationArray()

private static getTranslationArray(mixed $translation, mixed $length, mixed $timeString) : mixed
Parameters
$translation : mixed
$length : mixed
$timeString : mixed
Return values
mixed

Search results