Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
549 views
in Q2A Core by
Admin can change the locale for the whole site. The question is, is it possible to let end users do it themselves? Something like a language switcher at the right top corner of a page with a few languages to choose from?
by
It's not possible yet, and I haven't seen a plugin so far.

1 Answer

0 votes
by
edited by

I hacked core and realized it on my site.

Extra Userfield:
http://www.question2answer.org/qa/22728
Step1: Add "language" field of selection-box[drop-down] type.
Step2: Input lines to "Extra Settings" below.

@EVAL
require_once QA_INCLUDE_DIR.'qa-app-admin.php';
$options = qa_admin_language_options();
$extstr = '';
$next = false;
foreach($options as $key=>$option) {
  if($next) $extstr .= '||';
  $extstr .= $option . '==' . $key;
  $next = true;
}
return $extstr;

+

Core hack (add lines below):
qa-inclde/qa-base.php (L1024 [case V1.6.2])

// add [start]
$userid = qa_get_logged_in_userid();
if(isset($userid)) {
  if(!isset($_SESSION['qa_session_userlang'])) {
    $userprofile = qa_db_select_with_pending(qa_db_user_profile_selectspec($userid, true));
    if(array_key_exists('language', $userprofile))
      $_SESSION['qa_session_userlang'] = $userprofile['language'];
    else
      $_SESSION['qa_session_userlang'] = $languagecode;
  }
  $languagecode = $_SESSION['qa_session_userlang'];
}
// add [end]
Our users who registered can choose favorite language, but there is some issue in this hack. For example, email is sent to another user by the language that user chose. You may solve this issue by judging $identifier parameter of qa_lang() function.
...