interface LanguageManagerInterface (View source)

Common interface for the language manager service.

Methods

bool
isMultilingual()

Returns whether or not the site has more than one language added.

array
getLanguageTypes()

Returns an array of the available language types.

array
getDefinedLanguageTypesInfo()

Returns information about all defined language types.

getCurrentLanguage(string $type = LanguageInterface::TYPE_INTERFACE)

Returns the current language for the given type.

$this
reset(string|null $type = NULL)

Resets the given language type or all types if none specified.

getDefaultLanguage()

Returns a language object representing the site's default language.

getLanguages(int $flags = LanguageInterface::STATE_CONFIGURABLE)

Returns a list of languages set up on the site.

getNativeLanguages()

Returns a list of languages set up on the site in their native form.

getLanguage(string $langcode)

Returns a language object from the given language code.

string
getLanguageName(string $langcode)

Produced the printed name for a language for display.

getDefaultLockedLanguages(int $weight = 0)

Returns a list of the default locked languages.

bool
isLanguageLocked(string $langcode)

Checks whether a language is locked.

array
getFallbackCandidates(array $context = [])

Returns the language fallback candidates for a given context.

object|null
getLanguageSwitchLinks(string $type, Url $url)

Returns the language switch links for the given language type.

$this
setConfigOverrideLanguage(LanguageInterface $language = NULL)

Sets the configuration override language.

getConfigOverrideLanguage()

Gets the current configuration override language.

static array
getStandardLanguageList()

Some common languages with their English and native names.

Details

bool isMultilingual()

Returns whether or not the site has more than one language added.

Return Value

bool

TRUE if more than one language is added, FALSE otherwise.

array getLanguageTypes()

Returns an array of the available language types.

Return Value

array

An array of language type machine names.

array getDefinedLanguageTypesInfo()

Returns information about all defined language types.

Return Value

array

An associative array of language type information arrays keyed by language type machine name, in the format of hook_language_types_info(). In some implementing classes, this is based on information from hook_language_types_info() and hook_language_types_info_alter().

LanguageInterface getCurrentLanguage(string $type = LanguageInterface::TYPE_INTERFACE)

Returns the current language for the given type.

Parameters

string $type

(optional) The language type; e.g., the interface or the content language. Defaults to \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE.

Return Value

LanguageInterface

The current language object for the given type of language.

$this reset(string|null $type = NULL)

Resets the given language type or all types if none specified.

Parameters

string|null $type

(optional) The language type to reset as a string, e.g., LanguageInterface::TYPE_INTERFACE, or NULL to reset all language types. Defaults to NULL.

Return Value

$this

The language manager that has been reset.

LanguageInterface getDefaultLanguage()

Returns a language object representing the site's default language.

Return Value

LanguageInterface

A language object.

LanguageInterface[] getLanguages(int $flags = LanguageInterface::STATE_CONFIGURABLE)

Returns a list of languages set up on the site.

Parameters

int $flags

(optional) Specifies the state of the languages that have to be returned. It can be: LanguageInterface::STATE_CONFIGURABLE, LanguageInterface::STATE_LOCKED, or LanguageInterface::STATE_ALL.

Return Value

LanguageInterface[]

An associative array of languages, keyed by the language code.

LanguageInterface[] getNativeLanguages()

Returns a list of languages set up on the site in their native form.

Return Value

LanguageInterface[]

An associative array of languages, keyed by the language code, ordered by weight ascending and name ascending.

LanguageInterface|null getLanguage(string $langcode)

Returns a language object from the given language code.

Parameters

string $langcode

The language code.

Return Value

LanguageInterface|null

A fully-populated language object or NULL.

string getLanguageName(string $langcode)

Produced the printed name for a language for display.

Parameters

string $langcode

The language code.

Return Value

string

The printed name of the language.

LanguageInterface[] getDefaultLockedLanguages(int $weight = 0)

Returns a list of the default locked languages.

Parameters

int $weight

(optional) An integer value that is used as the start value for the weights of the locked languages.

Return Value

LanguageInterface[]

An array of language objects.

bool isLanguageLocked(string $langcode)

Checks whether a language is locked.

Parameters

string $langcode

The language code.

Return Value

bool

Returns whether the language is locked.

array getFallbackCandidates(array $context = [])

Returns the language fallback candidates for a given context.

Parameters

array $context

(optional) An associative array of data that can be useful to determine the fallback sequence. The following keys are used in core:

  • langcode: Language code of the desired language.
  • operation: The name of the operation indicating the context where language fallback is being applied. The following operations are defined in core, but more may be defined in contributed modules:
    • entity_view: Invoked when an entity is about to be displayed. The data key contains the loaded entity.
    • views_query: Invoked when a field based views query is performed. The data key contains a reference to the field object.
    • locale_lookup: Invoked when a string translation was not found. The data key contains the source string.
  • data: A data structure that makes sense in the provided context, see above.

Return Value

array

An array of language codes sorted by priority: first values should be tried first.

Returns the language switch links for the given language type.

Parameters

string $type

The language type.

Url $url

The URL the switch links will be relative to.

Return Value

object|null

An object with the following keys:

  • links: An array of links indexed by the language ID
  • method_id: The language negotiation method ID or NULL if there are no language switch links.

$this setConfigOverrideLanguage(LanguageInterface $language = NULL)

Sets the configuration override language.

Parameters

LanguageInterface $language

The language to override configuration with.

Return Value

$this

LanguageInterface getConfigOverrideLanguage()

Gets the current configuration override language.

Return Value

LanguageInterface

The current configuration override language.

static array getStandardLanguageList()

Some common languages with their English and native names.

Language codes are defined by the W3C language tags document for interoperability. Language codes typically have a language and, optionally, a script or regional variant name. See: http://www.w3.org/International/articles/language-tags/ for more information.

Return Value

array

An array of language code to language name information. Language name information itself is an array of English and native names.