Drupal: 7.19
ET: 7.x-1.x-dev (first, than downgraded to 7.x-1.0-beta2)
Pathauto: 7.x-1.2

Detection and selection (both user interface and content): Session only, node not use alias
Language switcher block (content) works, content language switches.
Switching language with content translation links works but adds ?language=[langcode] to the URL. After using content translation links language switcher (content) does not work, drupal stays on the same page (and the block on the same language).

Detection and selection (both user interface and content): Session only, node path aliased
Both Language switcher block (content) and Switching language with content translation links lead to "page not found". URL stays the same but the language changes in the switcher block.

Detection and selection (both user interface and content): URL (first) and Session (second), node path not aliased
Language switcher (content) does not work, Drupal stays on the same page (and the block on the same language).
Switching language with content translation link works, does not add anything to the URL.

Detection and selection (both user interface and content): URL (first) and Session (second), node path aliased
Language switcher (content) does not work, Drupal stays on the same page (and the block on the same language).
Switching language with content translation link works, does not add anything to the URL.

Comments

plach’s picture

I'm pretty sure at least one of the issues you are reporting is #1294946: Language detection based on session doesn't work with URL aliases.

thamas’s picture

Thanks for pointing to that issue. I looked for realated issues, but didn't find this. I'm sure they are related but there must be something more here…

Now I tested the swithching with URL only detection method and the lang switceher block does not work with this setting too. However I discerned that it switches the default language of the site in the background. Is it the normal, expected behaviour?

plach’s picture

AFAIK content language affects mostly the language fields are displayed in. Obviously if both UI and content language are configured to follow URL language the content language switcher will affect both fields and UI strings.

michaelkoehne’s picture

You can create a languageswitcher by yourself, here is a sample:

/**
 * Implements hook_block_info().
 */
function YOURMODULE_block_info() {
	$blocks = array();
	$blocks['languageswitcher'] = array(
		'info' => t('Customized Language Switcher'),
	);
	
	$blocks['toppages'] = array(
		'info' => t('Top Pages'),
	);

	return $blocks;
}


/**
 * Implements hook_block_view().
 */
function YOURMODULE_block_view($delta = '') {
	$block = array();
	global $language;
	
	switch($delta) {
		case 'languageswitcher':
			$block['subject'] = t('Switch your language:');
			$sql = "
				SELECT
					language,
					native
				FROM
					languages
				WHERE 
					enabled = 1
				ORDER BY
					weight ASC
			";
			$result = db_query($sql);
			
			$block['content'] = '<ul class="language-switcher-locale-url">';
			foreach($result as $row) {
				$block['content'] .= ($language->language == $row->language) ? '<li class="'.$row->language.' active">' : '<li class="'.$row->language.'">';
					$path = "";
					
					// $block['content'] .= arg(0);
					
					switch(true) {
						case (arg(0)=='taxonomy' && arg(1) == 'term'):
							// Für Terms
								$path = drupal_lookup_path('alias', 'taxonomy/term/'.(int)arg(2), $row->language);
							break;
						case (arg(0)=='node' && is_numeric(arg(1))):
							// Für Nodes
							$path = drupal_lookup_path('alias', 'node/'.(int)arg(1), $row->language);
							break;
						default:
							// Für Views und andere multilinguale Seiten
							$path = current_path();
					}
					
					if($path !== false ) {
						$block['content'] .= '<a href="/'.$row->language.'/'.$path.'">'.$row->native.'</a>';
					} else {
						$block['content'] .= '<a href="#" class="inactive">'.$row->native.'</a>';
					}
					
				$block['content'] .= '</li>';
			}
			$block['content'] .= '</ul>';
		
			break;
	}
	return $block;
}
qchan’s picture

Thanks mkweb!
You saved my life.

thamas’s picture

Issue summary: View changes
SilbinaryWolf’s picture

Updated mkwebs to just return it as array data, support table prefixes (required { }) and it supports links that don't use aliases.

function MYMODULE_get_languages() {
    $language_list = array();

    global $language;
    $language_default = language_default();

    // Force no-prefix when on other language pages
    // (Stops language prefix being applied on an alternate language page)
    global $language_url;
    $base_language_url = clone $language_url;
    $base_language_url->prefix = "";

    $sql = "SELECT language, native FROM {languages} WHERE enabled = 1 ORDER BY weight ASC";
    $result = db_query($sql);
    foreach($result as $row) 
    {
        $class = $row->language;
        $is_active = false;
        if ($language->language == $row->language) {
            $class .= " is-active";
            $is_active = true;
        }

        $path = "";
        if ($language_default->language != $row->language) {
            $url_options = array('prefix' => $row->language."/", 'absolute' => true, 'language' => $base_language_url);
        } else {
            // No prefix for default language
            $url_options = array('absolute' => true, 'language' => $base_language_url);
        }

        if (arg(0)=='taxonomy' && arg(1) == 'term')
        {
            // Terms
            $path = drupal_lookup_path('alias', 'taxonomy/term/'.(int)arg(2), $row->language);
            if ($path == false)
            {
                // Fallback to unaliased taxonomy
                $path = url('taxonomy/term/'.(int)arg(2), $url_options);
            }
        }
        else if (arg(0)=='node' && is_numeric(arg(1)))
        {
            // Nodes
            $path = drupal_lookup_path('alias', 'node/'.(int)arg(1), $row->language);
            if ($path == false)
            {
                // Fallback to unaliased node
                $path = url('node/' .(int)arg(1), $url_options);
            }
        }
        else
        {
            // Unknown
            $path = current_path();
        }

        $language_list[] = array(
            "title" => $row->native,
            "url"   => $path,
            "class" => $class,
            "is_active" => $is_active,
        );
    }
    return $language_list;
}
Yuri’s picture

After enabling the customized language switcher block, using code in #4 and #7, The switching does not apply the default language recognition settings. I have English as default site language, and that does not use the "/en/" url prefix.
Thus I get the error:
The requested page "/en/about" could not be found.