trait Options
Trait Options.
Embed base methods to change settings of Carbon classes.
Depends on the following methods:
Traits
Properties
staticprotectedTranslatorInterface | $translator | Default translator. | from Localization |
protectedTranslatorInterface | $localTranslator | Specific translator of the current instance. | from Localization |
staticprotectedint | $humanDiffOptions | Options for diffForHumans(). | from Localization |
staticint | $PHPIntSize | Customizable PHP_INT_SIZE override. | |
staticprotectedint|string | $weekStartsAt | First day of week. | |
staticprotectedint|string | $weekEndsAt | Last day of week. | |
staticprotectedarray | $weekendDays | Days of weekend. | |
staticprotectedarray |
$regexFormats | Format regex patterns. | |
staticprotectedarray | $regexFormatModifiers | Format modifiers (such as available in createFromFormat) regex patterns. | |
staticprotectedbool | $monthsOverflow | Indicates if months should be calculated with overflow. | |
staticprotectedbool | $yearsOverflow | Indicates if years should be calculated with overflow. | |
staticprotectedbool | $strictModeEnabled | Indicates if the strict mode is in use. | |
staticprotectedstring|callable|null | $formatFunction | Function to call instead of format. | |
staticprotectedstring|callable|null | $createFromFormatFunction | Function to call instead of createFromFormat. | |
staticprotectedstring|callable|null | $parseFunction | Function to call instead of parse. | |
protectedbool|null | $localMonthsOverflow | Indicates if months should be calculated with overflow. | |
protectedbool|null | $localYearsOverflow | Indicates if years should be calculated with overflow. | |
protectedbool|null | $localStrictModeEnabled | Indicates if the strict mode is in use. | |
protectedbool|null | $localHumanDiffOptions | Options for diffForHumans and forHumans methods. | |
protectedstring|null | $localToStringFormat | Format to use on string cast. | |
protectedstring|null | $localSerializer | Format to use on JSON serialization. | |
protectedarray|null | $localMacros | Instance-specific macros. | |
protectedarray|null | $localGenericMacros | Instance-specific generic macros. | |
protectedstring|callable|null | $localFormatFunction | Function to call instead of format. |
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.
Set the current translator locale and indicate if the source locale file exists.
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.
Returns true if the strict mode is globally in use, false else.
Get the month overflow global behavior (can be overridden in specific instances).
Get the month overflow global behavior (can be overridden in specific instances).
Returns current local settings.
Show truthy properties on var_dump().
No description
Set the timezone
Details
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat line104
staticint
getHumanDiffOptions()
Return default humanDiff() options (merged flags as integer).
inLocalizationat line114
staticTranslatorInterface
getTranslator()
Get the default translator instance in use.
inLocalizationat line126
staticvoid
setTranslator(TranslatorInterface$translator)
Set the default translator instance to use.
inLocalizationat line136
bool
hasLocalTranslator()
Return true if the current instance has its own translator.
inLocalizationat line146
TranslatorInterface
getLocalTranslator()
Get the translator of the current instance or the default if none set.
inLocalizationat line158
$this
setLocalTranslator(TranslatorInterface$translator)
Set the translator for the current instance.
inLocalizationat line175
staticstring
getTranslationMessageWith(TranslatorInterface$translator,string$key,string|null$locale =null,string|null$default =null)
Returns raw translation message for a given key.
inLocalizationat line203
string
getTranslationMessage(string$key,string|null$locale =null,string|null$default =null,TranslatorInterface$translator =null)
Returns raw translation message for a given key.
inLocalizationat line218
staticstring
translateWith(TranslatorInterface$translator,string$key,array$parameters =[],null$number =null)
Translate using translation string or callback available.
inLocalizationat 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.
inLocalizationat line270
string
translateNumber(int$number)
Returns the alternative number for a given integer if available in the current locale.
inLocalizationat 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.
inLocalizationat line425
string
translateTimeStringTo(string$timeString,string|null$to =null)
Translate a time string from the current locale ($date->locale()
) to an other.
inLocalizationat line438
$this|string
locale(string$locale =null,string...$fallbackLocales)
Get/set the locale for the current instance.
inLocalizationat line470
staticstring
getLocale()
Get the current translator locale.
inLocalizationat 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.
inLocalizationat line495
static
setFallbackLocale(string$locale)
Set the fallback locale.
inLocalizationat line520
staticstring|null
getFallbackLocale()
Get the fallback locale.
inLocalizationat 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).
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat 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.
inLocalizationat line661
staticarray
getAvailableLocales()
Returns the list of internally available locales and already loaded custom locales.
(It will ignore custom translator dynamic loading.)
inLocalizationat 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.
inLocalizationat line691
staticprotectedTranslatorInterface
translator()
Initialize the default translator instance if necessary.
inLocalizationat 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.
inLocalizationat line728
staticprotectedLocaleAwareInterface|null
getLocaleAwareTranslator(LocaleAwareInterface|null$translator =null)
Throw an error if passed object is not LocaleAwareInterface.
at line246
static
useStrictMode(bool$strictModeEnabled =true)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method.
at line257
staticbool
isStrictModeEnabled()
Returns true if the strict mode is globally in use, false else.
(It can be overridden in specific instances.)
at line275
staticvoid
useMonthsOverflow(bool$monthsOverflow =true)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).
at line291
staticvoid
resetMonthsOverflow()deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).
at line301
staticbool
shouldOverflowMonths()
Get the month overflow global behavior (can be overridden in specific instances).
at line319
staticvoid
useYearsOverflow(bool$yearsOverflow =true)deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).
at line335
staticvoid
resetYearsOverflow()deprecated
deprecated To avoid conflict between different third-party libraries, static setters should not be used. You should rather use the ->settings() method. Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants are available for quarters, years, decade, centuries, millennia (singular and plural forms).
at line345
staticbool
shouldOverflowYears()
Get the month overflow global behavior (can be overridden in specific instances).
at line367
$this|Options
settings(array$settings)
Set specific options.
- strictMode: true|false|null
- monthOverflow: true|false|null
- yearOverflow: true|false|null
- humanDiffOptions: int|null
- toStringFormat: string|Closure|null
- toJsonFormat: string|Closure|null
- locale: string|null
- timezone: \DateTimeZone|string|int|null
- macros: array|null
- genericMacros: array|null
at line405
array
getSettings()
Returns current local settings.
at line438
array
__debugInfo()
Show truthy properties on var_dump().
at line455
protected
addExtraDebugInfos($infos)
at line27
CarbonImmutable
shiftTimezone($timezone)
Set the timezone