Made Language block. How to copy language code of menu and put to my block.

Made Language block. How to copy language code of menu and put to my block.

by Mohammad kabir -
Number of replies: 4

Hi,

Moodle: 2.8.3

Theme : Bootstrapbase: 2.3.0

I made a language block to change language of the site(See the attachment.).  Menu exist but we made a block as well.

For the quiz, it cannot persist data for quiz number. In the query string, there is id, page number and so on, but no quiz number. How can I solve this?


How can I get the whole code of language menu so that  I can copy the code in my block?

Anybody can help thanks in advance.   

Attachment language block.png
Average of ratings: -
In reply to Mohammad kabir

Re: Made Language block. How to copy language code of menu and put to my block.

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

It generally helps if you share your code so that we can see and comment directly on it. From how I understand your situation, you want your block to use the current $PAGE->url and add the lang parameter to it to form the link to set the language and be redirected back to the same page.

In reply to David Mudrák

Re: Made Language block. How to copy language code of menu and put to my block.

by Mohammad kabir -

Hi David,

Here is the code below:

----------------------------------------

if ( !empty($_SERVER['QUERY_STRING'] ) && substr_compare( $_SERVER['QUERY_STRING'], 'lang', 0,4)  )

  {$page_url = $PAGE->url.'&'; }  

 else { $page_url = $PAGE->url.'?'; }

       

$this->content->items[] = html_writer::tag('a', 'English(En)', array('href' => $page_url.'lang=en'));

$this->content->icons[] = html_writer::empty_tag('img', array('src' => $images .'icons/United-Kingdom-flag-icon.png', 'alt'=>'United Kingdom flag icon', 'class' => 'icon'));

$this->content->items[] = html_writer::tag('a', 'NORSK-BOKMÅL(NO)', array('href' => $page_url.'lang=no'));

$this->content->icons[] = html_writer::empty_tag('img', array('src' => $images .'icons/norsk-flag-icon.png', 'alt'=>'norsk flag icon', 'class' => 'icon'));


-------------------------------------------------------------------------------------

It does not persist quiz number. Please find the attachment. I am in quiz number 4. And if now click on language option it starts from quiz no 1.        

Attachment lang_moodle.png
In reply to Mohammad kabir

Re: Made Language block. How to copy language code of menu and put to my block.

by Mohammad kabir -

Hi,

Still looking for solution. If anybody knows about this, would be helpful.

If need more explanation, please tell me.

Moodle: 2.8.3

Theme : Bootstrapbase: 2.3.0 

Thank you




In reply to Mohammad kabir

Re: Made Language block. How to copy language code of menu and put to my block.

by Mohammad kabir -

I found a bug:


<a href="https://nafo.localhost/mod/quiz/attempt.php?attempt=3632&amp;amp;page=2&amp;lang=en">English(En)</a>

<a href="https://nafo.localhost/mod/quiz/attempt.php?attempt=3632&amp;amp;page=2&amp;lang=no">NORSK-BOKMÅL(NO)</a>


There are double   "&amp;amp;".  str_replace("&amp;", "&" ... ) function could be a solution.  Is there any moodle function or ...?


Thank you