1 field.multilingual.inc field_valid_language($langcode, $default = TRUE)

Ensures that a given language code is valid.

Checks whether the given language is one of the enabled languages. Otherwise, it returns the current, global language; or the site's default language, if the additional parameter $default is TRUE.


$langcode: The language code to validate.

$default: Whether to return the default language code or the current language code in case $langcode is invalid.

Return value

A valid language code.:

Related topics


core/modules/field/field.multilingual.inc, line 241
Functions implementing Field API multilingual support.


function field_valid_language($langcode, $default = TRUE) {
  $enabled_languages = field_content_languages();
  if (in_array($langcode, $enabled_languages)) {
    return $langcode;
  global $language_content;
  return $default ? language_default()->langcode : $language_content->langcode;