7.x language.api.php hook_language_negotiation_info()

Define language negotiation providers.

Return value

An associative array of language negotiation provider definitions. The keys are provider identifiers, and the values are associative arrays defining each provider, with the following elements:

  • types: An array of allowed language types. If a language negotiation provider does not specify which language types it should be used with, it will be available for all the configurable language types.
  • callbacks: An associative array of functions that will be called to perform various tasks. Possible elements are:

    • language: (required) Name of the callback function that determines the language value.
    • switcher: (optional) Name of the callback function that determines links for a language switcher block associated with this provider. See language_switcher_url() for an example.
    • url_rewrite: (optional) Name of the callback function that provides URL rewriting, if needed by this provider.
  • file: The file where callback functions are defined (this file will be included before the callbacks are invoked).
  • weight: The default weight of the provider.
  • name: The translated human-readable name for the provider.
  • description: A translated longer description of the provider.
  • config: An internal path pointing to the provider's configuration page.
  • cache: The value Drupal's page cache should be set to for the current provider to be invoked.

See also


Related topics

2 functions implement hook_language_negotiation_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

locale_language_negotiation_info in modules/locale/locale.module
Implements hook_language_negotiation_info().
locale_test_language_negotiation_info in modules/locale/tests/locale_test.module
Implements hook_language_negotiation_info().
1 invocation of hook_language_negotiation_info()
language_negotiation_info in includes/language.inc
Returns all the defined language negotiation providers.


modules/system/language.api.php, line 140
Hooks provided by the base system for language support.


function hook_language_negotiation_info() {
  return array(
    'custom_language_provider' => array(
      'callbacks' => array(
        'language' => 'custom_language_provider_callback',
        'switcher' => 'custom_language_switcher_callback',
        'url_rewrite' => 'custom_language_url_rewrite_callback',
      'file' => drupal_get_path('module', 'custom') . '/custom.module',
      'weight' => -4,
      'types' => array(
      'name' => t('Custom language negotiation provider'),
      'description' => t('This is a custom language negotiation provider.'),
      'cache' => 0,


Patrick Bauer’s picture

Looks like the file key is required. Even if the callback function is in the same file it won't work.