I18n

class Nos\I18n

Provides the translation related functions.

::setLocale()

static Nos\I18n::setLocale($locale)

Configure the locale to use for translations.

Parameters:
  • $locale (string) – A valid locale (en, en_GB, en_GB.utf-8 and en_GB.utf-8@variant are all valid).

::restoreLocale()

static Nos\I18n::restoreLocale

Restores the previous locale.

::load()

static Nos\I18n::load($file)

Loads a dictionary for the current locale.

Parameters:
  • $file (string) – Dictionary path.
  • $group (string) – Group name. Default null, use $file.

::get()

static Nos\I18n::get($message, $default = null)

Retrieves a translation from the last loaded dictionary.

Parameters:
  • $message (string) – The message to translate.
  • $default (string) – The default text to return when the message is not found. Default value is the message itself.
Returns:

The translation or null if not founded

::gget()

static Nos\I18n::gget($file, $message, $default = null)

Retrieves a translation from a specific dictionary.

Parameters:
  • $file (string) – Which dictionary to look into.
  • $message (string) – The message to translate.
  • $default (string) – The default text to return when the message is not found. Default value is the message itself.
Returns:

The translation or null if not founded

Warning

The dictionary must have been loaded manually before.

::nget()

static Nos\I18n::nget($singular, $plural, $n)

The plural version of I18n::get. Some languages have more than one form for plural messages dependent on the count.

Parameters:
  • $singular (string) – The singular form of the string to be converted. Used as the key for the search in the dictionary
  • $plural (string) – The plural form
  • $n (string) – Used to determine which plural form to used depending locale.
Returns:

The translation or, if not founded, $singular is returned if n == 1, otherwise $plural

::ngget()

static Nos\I18n::gget($group, $singular, $plural, $n)

Retrieves a plural translation from a specific dictionary.

Parameters:
  • $group (string) – Which dictionary to look into.
  • $singular (string) – The singular form of the string to be converted. Used as the key for the search in the dictionary
  • $plural (string) – The plural form
  • $n (string) – Used to determine which plural form to used depending locale.
Returns:

The translation or, if not founded, $singular is returned if n == 1, otherwise $plural

Warning

The dictionary must have been loaded manually before.

::current_dictionary()

static Nos\I18n::current_dictionary($list)

Set the current dictionary

Parameters:
  • $list (string|array) – A dictionary file or list of dictionaries.

::dictionary()

static Nos\I18n::dictionary($files)

Returns a closure that translate messages from a specific dictionary.

Parameters:
  • $files (string|array) – A dictionary file or list of dictionaries.
Returns:

A callable to translate a message

<?php

// Retrieves an anonymous function
$dictionary = Nos\I18n::dictionary('mon_appli::common');

echo $dictionary('Translate this');

::addPriorityDictionary()

static Nos\I18n::addPriorityDictionary($locale, $dictionary)

Add a priority dictionary for a locale

Parameters:
  • $locale (string) – A valid locale
  • $dictionary (string) – Dictionary path

::addPriorityMessages()

static Nos\I18n::addPriorityMessages($locale, $messages)

Add some priorities translations for a locale

Parameters:
  • $locale (string) – A valid locale
  • $messages (array) – An array of translations
Read the Docs v: dubrovka
Versions
latest
elche
dubrovka
chiba.2
chiba.1
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.