• PHP reference

Language

class Language extends ExtendableObject

Handles translations, showing dates, time differences and other locale-related information.

Properties

static string $locale

Current locale.

static string $standardLocale

Fallback locale.

Methods

__construct(string $locale = null, string $standardLocale = null)

Constructor.

Parameters

  • string $locale
  • string $standardLocale

setLocale(string $locale)

Set the locale.

Parameters

  • string $locale

setStandardLocale(string $standardLocale)

Set the fallback locale.

Parameters

  • string $standardLocale

string translate(string|string[] $string)

Translate a string with the current locale.

Parameters

  • string|string[] $string

Return Value

  • string

static string translateWithLocale(string $locale, string $string, array $args = [])

Find a translation for a certain string in a certain locale.

Falls back to the standard locale or the string value if no translation can be found.

Parameters

  • string $locale
  • string $string
  • array $args

Return Value

  • string

static array addTranslation(string $locale, string $original, string $translation)

Add a translation to the translations cache.

Parameters

  • string $locale
  • string $original
  • string $translation

Return Value

  • array

static array get_translations_from_file(string $locale, string $filename, boolean $return = false)

Load and decode translations from a specific file.

Parameters

  • string $locale
  • string $filename
  • boolean $return

Return Value

  • array

string date(integer $time = null, string $format = 'short')

Show a formatted date.

Parameters

  • integer $time
  • string $format

Return Value

  • string

mixed country_code()

Get two-letter country code for current locale (lowercase).

Return Value

  • mixed

mixed language_code()

Get two-letter language code for current locale (lowercase).

Return Value

  • mixed

mixed language_name()

Get the name of the current locale's language.

Return Value

  • mixed

mixed timeago(integer $time = null)

Get a relative date for a timestamp in the past.

Parameters

  • integer $time

Return Value

  • mixed

mixed timeleft(integer $time = null)

Get a relative date string for a timestamp in the future (opposite of timeago).

Parameters

  • integer $time

Return Value

  • mixed

string currency(float $amount, boolean $spacing = true)

Format a price.

Parameters

  • float $amount
  • boolean $spacing

Return Value

  • string

static string pluralize(integer|float $count, string $singular, string|boolean $plural = false)

Conditionally pluralize a string.

Parameters

  • integer|float $count
  • string $singular
  • string|boolean $plural

Return Value

  • string

Inherited from ExtendableObject

final static ExtendableObject instance()

Get instance.

Return Value

final static boolean hasInstance()

Check whether there is an instance of this class available.

Return Value

  • boolean

final boolean extension($extension)

Call class method, if it exists.

Parameters

  • $extension

Return Value

  • boolean