Skip to content

Instantly share code, notes, and snippets.

@ClaudioVarandas
Created January 25, 2017 12:26
Show Gist options
  • Save ClaudioVarandas/e125c66358117d58cba3a14a21e11780 to your computer and use it in GitHub Desktop.
Save ClaudioVarandas/e125c66358117d58cba3a14a21e11780 to your computer and use it in GitHub Desktop.
Drupal language custom provider
<?php
/**
* @file
* Handles localization for module.
*/
/**
* Language callback for selecting the active language.
*/
function MODULE_language_provider_callback($languages) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
list($language, $_GET['q']) = language_url_split_prefix(isset($_GET['q']) ? $_GET['q'] : NULL, $languages);
if ($language === FALSE && isset($languages['pt-pt'])) {
return $languages['pt-pt']->language;
}
return locale_language_from_url($languages);
}
/**
* Language callback for language switcher.
*/
function MODULE_language_switcher_callback($type, $path) {
return locale_language_switcher_url($type, $path);
}
/**
* Language callback for URL rewrite.
*/
function MODULE_language_url_rewrite_callback(&$path, &$options) {
locale_language_url_rewrite_url($path, $options);
if (empty($options['language'])) {
return;
}
switch ($options['language']->language) {
case 'pt-pt':
$options['prefix'] = '';
break;
default:
$options['prefix'] = $options['language']->language . '/';
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment