HTML code for switching between two languages from current page

HTML code for switching between two languages from current page

by Tan Dai Nguyen -
Number of replies: 6
Hi everybody,

I'd like to create an HTML block in the frontpage for direct switching between two languages from any current page on the frontpage course. I've found some interesting similar ideas, but what I want to do is a little different: how to get the current filepath, filename and itemid (eg. http://mysite.com/moodle/mod/resource/view.php?id=6936) by HTML code, so I can add the suffix '&lang=xx' for direct switching language on this current page.

The expected result is that when the user change to another page, he/she can always see the HTML block, where the language switching suffix does not change but only the filepath, filename and itemid. With this function, the user does not need to return to the index page everytime he/she want to change the prefered language.

May you help me to learn about this?
Average of ratings: -
In reply to Tan Dai Nguyen

Re: HTML code for switching between two languages from current page

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just a thought, but instead of doing this as a block, you could include the change language links in the header.html file of your theme.

Anyway, in Moodle 1.9, you can get the URL of the current page by using the fullme() function or the $FULLME global, and then add &lang=xx to that. (In Moodle 2.0, use $PAGE->url instead of $FULLME.)
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: HTML code for switching between two languages from current page

by Tan Dai Nguyen -
Thank you for your suggestion. I think that I should directly modify the header.html file. The codes do not work with an HTML bloc.
In reply to Tim Hunt

Re: HTML code for switching between two languages from current page

by lisa madmood -

Good morning,

I've just posted my problem today and now I see this very very interesting solution, that could resolve half of my problem !

Tim please, could you give me the complete code for Moodle 1.9 to get the url of the current page (because it's not very clear for me ) ? I have this code on the mainmenu-top.php file of my theme  (include in my header file) :

<?php

echo '<div id="mainmenu-langopt">';
if (empty($CFG->langmenu)) {
$langmenu = '';
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$langlabel = get_accesshide(get_string('language'));
$langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
}
echo $langmenu;
echo '</div>';

?>

What may I modify exactly ?

Many thanks.

Best regards.

In reply to lisa madmood

Re: HTML code for switching between two languages from current page

by Sarah Jane -

Hi Lisa I came across your post in moodle regarding the switch between 2 languages. Did you complete this task? May I trouble you to ask how you did this? I am working in the latest version of moodle 2.4

Many thanks

Sarah x

In reply to Sarah Jane

Re: HTML code for switching between two languages from current page

by Sarah Jane -

Guys,

If anyone can help me with this I would be grateful. I wish to be able to use the two languages German and English if someone can guide me on how to do this. I have read all the forums I can find but many of these are so old I am not sure there solution would be helpful for the latest moodle version 2.4

Thanking you in advanced. Sarah x