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
Return default humanDiff() options (merged flags as integer).
Get the default translator instance in use.
Set the default translator instance to use.
Return true if the current instance has its own translator.
Get the translator of the current instance or the default if none set.
Set the translator for the current instance.
Returns raw translation message for a given key.
Returns raw translation message for a given key.
Translate using translation string or callback available.
Translate using translation string or callback available.
Returns the alternative number for a given integer if available in the current locale.
Translate a time string from a locale to an other.
Translate a time string from the current locale ($date->locale()
) to an other.
Get/set the locale for the current instance.
Get the current translator locale.
Set the current translator locale and indicate if the source locale file exists.
Set the fallback locale.
Get the fallback locale.
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).
Returns true if the given locale is internally supported and has short-units support.
Returns true if the given locale is internally supported and has diff syntax support (ago, from now, before, after).
Returns true if the given locale is internally supported and has words for 1-day diff (just now, yesterday, tomorrow).
Returns true if the given locale is internally supported and has words for 2-days diff (before yesterday, after tomorrow).
Returns true if the given locale is internally supported and has period syntax support (X times, every X, from X, to X).
Returns the list of internally available locales and already loaded custom locales.
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.
Initialize the default translator instance if necessary.
Get the locale of a given translator.
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.
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.
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.
at line104
staticint
getHumanDiffOptions()
Return default humanDiff() options (merged flags as integer).
at line114
staticTranslatorInterface
getTranslator()
Get the default translator instance in use.
at line126
staticvoid
setTranslator(TranslatorInterface$translator)
Set the default translator instance to use.
at line136
bool
hasLocalTranslator()
Return true if the current instance has its own translator.
at line146
TranslatorInterface
getLocalTranslator()
Get the translator of the current instance or the default if none set.
at line158
$this
setLocalTranslator(TranslatorInterface$translator)
Set the translator for the current instance.
at line175
staticstring
getTranslationMessageWith(TranslatorInterface$translator,string$key,string|null$locale =null,string|null$default =null)
Returns raw translation message for a given key.
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.
at line218
staticstring
translateWith(TranslatorInterface$translator,string$key,array$parameters =[],null$number =null)
Translate using translation string or callback available.
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.
at line270
string
translateNumber(int$number)
Returns the alternative number for a given integer if available in the current locale.
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.
at line425
string
translateTimeStringTo(string$timeString,string|null$to =null)
Translate a time string from the current locale ($date->locale()
) to an other.
at line438
$this|string
locale(string$locale =null,string...$fallbackLocales)
Get/set the locale for the current instance.
at line470
staticstring
getLocale()
Get the current translator locale.
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.
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).
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.
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.
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.
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.
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.
at line661
staticarray
getAvailableLocales()
Returns the list of internally available locales and already loaded custom locales.
(It will ignore custom translator dynamic loading.)
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.
at line691
staticprotectedTranslatorInterface
translator()
Initialize the default translator instance if necessary.
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.
at line728
staticprotectedLocaleAwareInterface|null
getLocaleAwareTranslator(LocaleAwareInterface|null$translator =null)
Throw an error if passed object is not LocaleAwareInterface.