You are here

function og_set_language in Organic groups 6.2

Same name and namespace in other branches
  1. 6 og.module \og_set_language()

Set the language for the page based on group's language.

Will have no effect if user has set a personal language or a URL language domain/prefix.

Parameters

string $node: Node object of the group.

See also

language_initialize().

1 call to og_set_language()
og_set_group_context in ./og.module
API function to set the group context for the current request.

File

./og.module, line 584
Code for the Organic Groups module.

Code

function og_set_language($node) {

  // If group specifies language, and the URL does not:
  if ($node->og_language) {

    // Configured presentation language mode.
    $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);

    // Get a list of enabled languages.
    $languages = language_list('enabled');
    $languages = $languages[1];

    // Set to true if the url holds a language designator.
    $url_set = FALSE;

    // Check whether the URL holds a language domain/prefix.
    switch ($mode) {
      case LANGUAGE_NEGOTIATION_DOMAIN:
        foreach ($languages as $language) {
          $parts = parse_url($language->domain);
          if (!empty($parts['host']) && $_SERVER['HTTP_HOST'] == $parts['host']) {
            $url_set = TRUE;
            break;
          }
        }
        break;
      case LANGUAGE_NEGOTIATION_PATH:

        // Uses $_REQUEST as language_initialize removes prefix from $_GET
        $args = isset($_REQUEST['q']) ? explode('/', $_REQUEST['q']) : array();
        $prefix = array_shift($args);

        // Search prefix within enabled languages.
        foreach ($languages as $language) {
          if (!empty($language->prefix) && $language->prefix == $prefix) {
            $url_set = TRUE;
            break;
          }
        }
        break;
    }
    if ($url_set) {
      return;
    }
    $og_language = $languages[$node->og_language];
    global $user;
    $user_language = user_preferred_language($user, $og_language);
    if ($og_language == $user_language) {
      $GLOBALS['language'] = $og_language;
    }
  }
}