You are here

function i18n_language_context in Internationalization 7

Get / set language from current context / content.

Depending on the page content we may need to use a different language for some operations.

This should be the language of the specific page content. I.e. node language for node pages or term language for taxonomy term page.

Parameters

$language: Optional language object to set for context.

Return value

Context language object, which defaults to content language.

See also

hook_i18n_context_language().

2 calls to i18n_language_context()
i18n_taxonomy_allowed_values in i18n_taxonomy/i18n_taxonomy.module
Returns the set of valid terms for a taxonomy field.
i18n_taxonomy_form_taxonomy_form_term_alter in i18n_taxonomy/i18n_taxonomy.module
Implements hook_form_FORM_ID_alter()
1 string reference to 'i18n_language_context'
i18n.module in ./i18n.module
Internationalization (i18n) module.

File

./i18n.module, line 131
Internationalization (i18n) module.

Code

function i18n_language_context($language = NULL) {
  if ($language) {
    $GLOBALS[I18N_LANGUAGE_TYPE_CONTEXT] = $language;
  }
  elseif (!isset($GLOBALS[I18N_LANGUAGE_TYPE_CONTEXT])) {

    // It will default to content language.
    $GLOBALS[I18N_LANGUAGE_TYPE_CONTEXT] = i18n_language_content();

    // Get language from the first module that provides it.
    foreach (module_implements('i18n_context_language') as $module) {
      if ($language = module_invoke($module, 'i18n_context_language')) {
        $GLOBALS[I18N_LANGUAGE_TYPE_CONTEXT] = $language;
        break;
      }
    }
  }
  return $GLOBALS[I18N_LANGUAGE_TYPE_CONTEXT];
}