Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+6 votes
1.7k views
in Q2A Core by
I saw instructions for this for V1.2 I am wondering if this will work for V1.3?
related to an answer for: How to change language dynamically
by
I verify it at new V1.3 environment(My environment updated from old version). Please wait for a while.

4 Answers

+4 votes
by
edited by
 
Best answer

Below code is language + theme changer for V1.3

See SelectionBox at Top-right.
 
---------------------------------------------------------------
【URL parameter read】
Source: qa-include/qa-base.php
find:
$languagecode=qa_opt('site_language');
add after:
$qa_lang=qa_get('qa_lang'); // get from URL parameter if possible
if (isset($qa_lang)) // otherwise get option
  $languagecode=$qa_lang;
---
Source: qa-include/qa-page.php
find:
$themeclass=qa_load_theme_class(qa_opt('site_theme'), $qa_template, $qa_content, $qa_request);
replace:
$qa_theme=qa_get('qa_theme'); // get from URL parameter if possible
if (!isset($qa_theme)) // otherwise get option
  $qa_theme=qa_opt('site_theme');
$themeclass=qa_load_theme_class($qa_theme, $qa_template, $qa_content, $qa_request);
---------------------------------------------------------------
【URL parameter restore】
Source: qa-include/qa-base.php
find:
global $qa_root_url_relative;
add after:
$qa_theme=qa_get('qa_theme');
if (isset($qa_theme))
  @$params['qa_theme']=$qa_theme;
$qa_lang=qa_get('qa_lang');
if (isset($qa_lang))
  @$params['qa_lang']=$qa_lang;
---------------------------------------------------------------
【Display HTML】
---
Source: qa-include/qa-page.php
find:
$themeclass->output('>');
add after:
$themeclass->changer();
---
Source: qa-include/qa-theme-base.php
find:
function c_item_clear()
{
  $this->output(
  '<DIV CLASS="qa-c-item-clear">',
  '</DIV>'
  );
}
add after below function:
function changer() {
  require_once QA_INCLUDE_DIR.'qa-app-admin.php';
 
  // Lang: Get and Set URL parameter OR System settings
  $qa_lang=qa_get('qa_lang');
  if (!isset($qa_lang))
    $qa_lang=qa_opt('site_language');
  $langParam='&amp;qa_lang='.$qa_lang;
  $langOptions = qa_admin_language_options();
  foreach($langOptions as $key => $val)
    $langArray[] = array('name'=>$val, 'value'=>$key, 'selected'=>'');
  $found = false;
  $index = 0;
  foreach($langArray as $langItem){
    foreach($langItem as $key => $val){
      if ($key=='value' && $val==$qa_lang){
        $langArray[$index]['selected']='selected="selected"';
        $found = true;
        break 2;
      }
    }
    $index++;
  }
  if(!$found) $langArray[0]['selected']='selected="selected"';
 
  // Theme: Get and Set URL parameter OR System settings
  $qa_theme=qa_get('qa_theme');
  if (!isset($qa_theme))
    $qa_theme=qa_opt('site_theme');
  $themeParam='&amp;qa_theme='.$qa_theme;
  $themeOptions = qa_admin_theme_options();
  foreach($themeOptions as $key => $val)
    $themeArray[] = array('name'=>$val, 'value'=>$key, 'selected'=>'');
  $found = false;
  $index = 0;
  foreach($themeArray as $themeItem){
    foreach($themeItem as $key => $val){
      if ($key=='value' && $val==$qa_theme){
        $themeArray[$index]['selected']='selected="selected"';
        $found = true;
        break 2;
      }
    }
    $index++;
  }
  if(!$found) $themeArray[0]['selected']='selected="selected"';
 
  // Output option bar
  $this->output('<DIV class="qa-changer" style="padding:0;margin:0 auto;text-align:right;width:980px;height:32px;">');
$this->output('<DIV class="qa-changer-block" style="display:inline;">
  <SPAN class="qa-changer-title" style="">Language:</SPAN>
  <SELECT class="qa-changer-selector" style="" name="qa-changer-select-lang" onchange="location.href=\'?&amp;qa_lang=\'+this.options[this.selectedIndex].value+\''.$themeParam.'\'">');
  foreach($langArray as $langItem)
    $this->output('<OPTION class="qa-changer-selector-option" value="'. $langItem['value'] .'" '. $langItem['selected'] .'>'.$langItem['name'].'</OPTION>');
  $this->output('</SELECT>');
  $this->output('</DIV>');
  $this->output('<DIV class="qa-changer-block"  style="display:inline;">
  <SPAN class="qa-changer-title" style="">Theme:</SPAN>
  <SELECT class="qa-changer-selector" style="" name="qa-ts-selector-theme" onchange="location.href=\'?'.$langParam.'&amp;qa_theme=\'+this.options[this.selectedIndex].value">');
  foreach($themeArray as $themeItem)
    $this->output('<OPTION class="qa-changer-selector-option" value="'. $themeItem['value'] .'" '. $themeItem['selected'] .'>'.$themeItem['name'].'</OPTION>');
  $this->output('</SELECT>');
  $this->output('</DIV>');
  $this->output('</DIV>');
}
---
by
Brilliant! Thanks, it works perfectly.
by
After switch language, url allways display as old link, so language is also the default language

Demo:
http://www.joomla178.com/ask/?&qa_lang=zh-TW
http://www.joomla178.com/ask/?&qa_lang=zh

Solved:

Find code:

$requestpath=implode('/', $requestparts);

Replace:

$qa_lang=qa_get('qa_lang'); // get from URL parameter if possible
$requestpath=implode('/', $requestparts).'&qa_lang='.$qa_lang;
by
Hi Sama, Will this work with v. 1.7?
0 votes
by

It doesn't work sad

Fatal error: Call to undefined method qa_html_theme::changer()

Has anyone implemented this on V1.3?

+3 votes
by
It would be awesome to have a multilingual setup out of the box or trough a plugin. I'm always reluctant to change the code - it's always a hassle after each update.
+1 vote
by

 

After switch language, url allways display as old link, so language is also the default language

Demo: http://www.joomla178.com/ask/?&qa_lang=zh-TW and http://www.joomla178.com/ask/?&qa_lang=zh

Solved:

Find code:

$requestpath=implode('/', $requestparts);

Replace:

 

$qa_lang=qa_get('qa_lang'); // get from URL parameter if possible
$requestpath=implode('/', $requestparts).'&qa_lang='.$qa_lang;

 

by
this worked for me (v 1.6.3).

i added below two lines:
$qa_lang=qa_get('qa_lang'); // get from URL parameter if possible
$params['qa_lang'] = $qa_lang;

before:
$requestpath=implode('/', $requestparts);
...