1.20.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 Backdrop's page cache should be set to for the current provider to be invoked.

See also

hook_language_negotiation_info_alter()

Related topics

File

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

Code

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' => backdrop_get_path('module', 'custom') . '/custom.module',
      'weight' => -4,
      'types' => array('custom_language_type'),
      'name' => t('Custom language negotiation provider'),
      'description' => t('This is a custom language negotiation provider.'),
      'cache' => 0,
    ),
  );
}