Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I have created a drop-down language switcher. I automatically switches languages on selecting a new option from the drop-down.
<?php
$query = drupal_query_string_encode($_GET, array('q'));
$path = $_GET['q'];
$lang = translation_get_links($path, empty($query) ? NULL : $query);
$current_lang = i18n_get_lang(); // Look up current language with a call to this i18n function, setup link array elements.
$active_lang = i18n_languages('active'); // loop up al enabled languages
$names = i18n_languages('native'); //look up alll native names
?>
<form action="">
<select name="language" onchange="window.location.href='/'+this.options[this.selectedIndex].value;">
<?php
foreach (array_keys($active_lang) as $lang){
$url = translation_url($path, $lang);
$output = '<option ';
if ($lang == $current_lang) {
$output .= 'selected ';
}
$output .= 'value="';
$output .= i18n_path($url.'?'.$query , $lang);
$output .= '">';
$output .= $names[$lang];
$output .= '</option>';
print $output;
}
?></select>
</form>
Comments
Javascript language select on D6
Here's what I shoved into the page template on www.cai.org (Drupal 6):
I used CSS to put the language flag image next to the select list, but you can cut that bit out if you like. I doubt it's the most efficient or best-written code so improvements are welcome. However it works at least!
the spanish flag on ur front
the spanish flag on ur front page links to the root, without es/
figured u might wanna change that ;)
and I changed the img to be something like this:
coz I use a lotta subfolders n shit for multiple drupal installs on the same host, and the current language variable u used didn't return anything for me, so I used the i18n function
not sure if this also works for D6 though, I'm too scared to try :p
thx for the drop-down menu stuffs, saving me at least an hour \o/
if ur website isn't on the root of ur host (e.g. http://www.example.com) but instead it's located in a subfolder (e.g. http://www.example.com/website/) u might wanna change
into
Language Switcher Reverts to Hebrew on Hebrew Enabled Browsers
I developed a Drupal 6.2 site which switches between three languages via a drop-down menu. (See www.itwrite.com)
The default site language is English, and the other two languages are Dutch and Hebrew. The site uses no "en" site name extension for English, but "nl" and "he" extensions for Dutch and Hebrew. The
drupal_get_path_alias($drupal_path, $lang);
function to access the language extension for a particular language didn't work for me. And so, I bypassed the function and hard-coded language selection via the select element. (I didn't mind this as I know which languages I'll be using).I used the following section of code:
Everything works fine and languages switch OK on English or other language enabled browsers in both IE and Firefox browsers. However, on a Hebrew enabled XP machine when I select English via the drop-down menu (on both IE and Firefox browsers) the language always reverts to Hebrew only if English is selected. (This does not happen with Dutch.) So I'm unable to access the English based section of the site through any Hebrew enabled browsers.
My guess is that the language negotiation mechanism somehow detects the browser's primary language (i.e. Hebrew), and since the browser language is given a "higher priority" over English - the language defaults to the browser language instead of applying the user's selected language.
Is there any way of disabling this language fallback mechanism? Is there something I'm missing here? Can it be explained? I don't mind putting an "en" extension to the site for English, if that will do the trick? How do I do that? Maybe there are better ways.
Appreciate any assistance.
Regards,
Moses
=====
Sorry, figured it out. Setting language preference to "Path prefix only", instead of "Path prefix with language fallback" fixed it, and now it works fine. Hope this helps someone else.
Regards,
Moses
Don't return languages
fletchgqc
displaying the block
returns an empty array. Array ( ).
P.s I have Alias URL active and I tried viewing on a node translated.
Update
Maybe this will help... I updated our code as follows, to ensure the languages are ordered correctly in the drop-down list. Try this code out.
Hi, Could you advice how I
Hi,
Could you advice how I can use it if I don't have translation.module?
I use i18n+languageicons and when I put your code I have only one language in drop-down menu (current), but I have much more languages.
Thanks!
Where to put this code?
Hello fletchgqc,
Can you tell me where to put this code?
Thanks in advance.
Just what I need, but where
Just what I need, but where do I put the code?
you'll need to apply a translation.module patch
Seemingly random nodes populate this dropdown if the node being viewed does not have a translation.
The patch and the explanation of why are here: http://drupal.org/node/289502
I spent the better part of a few hours trying to figure this thing out.
That made me register and post this comment so hopefully you don't have to do the same!
showing selected language
i want to show the translation only 2 language of 4 language enable
language dropdown
Hi this is working great. thanks for this. But I noticed that when going to the page like "contact us" the drop down only shows "english" language. Can you help me fix this. Thanks
This is my solution for this, hope it helps, PEACE :)
Language Switcher Dropdown
This ends the pain for D6
http://drupal.org/project/lang_dropdown
Mohammed J. Razem
http://www.vardot.com
looks like lang_dropdown only
looks like lang_dropdown only switches interface, not content.... digging this