Quick switch between languages from any page of the site

Quick switch between languages from any page of the site

by Cristobal Gomez -
Number of replies: 4
Hi everybody,

I'm new at the community and I'm running a small moodle community, but I needed to find a quick way of switching between languages, so I can display the lesson or quizz that I'm explaining to the class in the different languages.

After looking for a solution, I've found that there isn't (at least I couldn't find it) a quick plugin or solution for this matter (maybe I'm wrong)

I found at this link that you can change the language simply adding to the current url "&lang=xx" where the xx are the desired language (of course you need to have some content in that language and/if you want moodle to look like the selected language, the package)

So I inserted the following code to the header and works pretty good for me in any path of the site,

<a href="<?php
# Using REQUEST_URI

echo "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

?>&lang=es">Spanish</a>

(you can repeat the code for any language and add other link)

but (there is alwas a "but" :p) if you keep changing the language, you'll find a very long url, because everytime add the &lang=xx code, so it would look like this:

/moodle/mod/quiz/attempt.php?id=40&lang=es&lang=kh_cn&lang=zh_cn&lang=en&lang=es&lang=zh_cn&lang=en&lang=zh_cn&lang=es&lang=en&lang=es&lang=zh_cn&lang=en&lang=zh_cn&lang=es&lang=zh_cn&lang=en&lang=es&lang=es&lang=zh_cn&lang=en

and over and over. so this is not an elegant solution, for the moment it fix the problem, but it isn't as elegant as the main page option to change the language.

So if anybody knows a better solution I would be very thankful.

Thanks for your time.
Average of ratings: -
In reply to Cristobal Gomez

Re: Quick switch between languages from any page of the site

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Cristobal:

I needed to find a quick way of switching between languages, so I can display the lesson or quizz that I'm explaining to the class in the different languages

If I understand you correctly, you are actually using your Moodle course in a face-to-face class, displaying the screen onto a video-projector (or to the students' screen in a language lab) ? And you need to be able to switch instantly from one language to another, without having to quit the current course and go to your moodle site front page to select a language from the languages drop-down list?

If that is the case, then there is a very easy answer.

Open another intance of your moodle site in another window (or tab) and display the front page. Every time you need to switch languages, just switch windows (or tabs), change the language and go back to the course where you are demonstrating the lesson or quiz (remember to refresh that window for the new language setting to take effect).

I hope that helps,

Joseph

In reply to Cristobal Gomez

Re: Quick switch between languages from any page of the site

by Robert Brenstein -
If Joseph's suggestion does not satisfy you, check the header file in your theme for the command that inserts the language switching menu for the front page. You could clone that part of the code to display on your course page, actually in your case it seems on every page. You may need to use a variation of the function called in order for it to work on any page. I vaguely recall someone discussing such an implementation somewhere on moodle.org.
In reply to Cristobal Gomez

Re: Quick switch between languages from any page of the site

by Cristobal Gomez -
Thanks both for your answers, Joseph, as you are guessing, you are right, I'm using moodle for a driving school and we need to explain the quizzes to the people, so yes, the teacher is in front of the classroom showing the screen in a proyector.

Your choice is good, but the teachers that are working at the school are not used to computers, so I need to make it easy in order to loose as less time as possible, for me would be a good choice, but not for the school.

I'm going to try the method that Robert suggest, but I'm no good with php (I need to learn) so I don't know what I need to change at the command that inserts the language switching so it doesn't send me everytime to the home page. I'm going to work on it.

Also I would need that once the page reloads go to the same question that the teacher was explainig, so maybe I need to put the switch button in everyquestion in order for the teacher to change the language in an easy way. I don't know, I'll post here my definitive solution so it can help to anyone that is in the same need in the future, meanwhile I'm all ears for any solution you suggest.

By the way, Do you know where should I put the code to display the languages options in every question? thanks.

Thanks everybody.
In reply to Cristobal Gomez

Re: Quick switch between languages from any page of the site

by Cristobal Gomez -
Hi again everybody,

I've been looking and it seems that the code for the language switch option at the index page is as follows

if (empty($CFG->langmenu)) {
$langmenu = "";
} else {
$currlang = current_language();
$langs = get_list_of_languages();
$langlabel = get_accesshide(get_string('language'));
$langmenu = popup_form ("$CFG->httpswwwroot/login/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true, 'self', $langlabel);
}

I've putted at the header, but no luck, I assume I need to modify something in order to make the selector appear.

Thanks.