Page MenuHomePhabricator

Language selection does not change the Content-language
Open, MediumPublic

Description

Author: bugzilla

Description:
I have a closed-full translated wiki. It wold be very helpful if the LanguageSelector can also switch the content-language.

Following code in LanguageSelector.php works very well for us:

//________________________________________________
define( 'LANGUAGE_SELECTOR_ADJUST_CONTENT', 1 );

$wgHooks['BeforeInitialize'][] = 'wfLanguageSelectorAdjustContent';

function wfLanguageSelectorAdjustContent( &$title, &$article, &$output, &$user, $request, $this ) {

global $wgLanguageSelectorRequestedLanguage, $wgLanguageNames, $wgLanguageSelectorAdjustContent;
if( isset($wgLanguageSelectorAdjustContent) && $wgLanguageSelectorAdjustContent=== LANGUAGE_SELECTOR_ADJUST_CONTENT){
  $langstr="/".$wgLanguageSelectorRequestedLanguage;
  $searchstr="#/(". implode('|',array_keys($wgLanguageNames)) ."$)#";
  $title->mTextform =preg_replace($searchstr,$langstr, $title->mTextform);
  $title->mUrlform =preg_replace($searchstr,$langstr, $title->mUrlform);
  $title->mDbkeyform =preg_replace($searchstr,$langstr, $title->mDbkeyform);
  $title->mUserCaseDBKey =preg_replace($searchstr,$langstr, $title->mUserCaseDBKey);
}
return true;

}

//________________________________________________

So i can switch the new behavior in the LocalSettings.

$wgLanguageSelectorAdjustContent= LANGUAGE_SELECTOR_ADJUST_CONTENT;

Please let me know if you can add this to the next release or better to 1_17?


Version: unspecified
Severity: normal
See Also:
T63695: Selecting a different language should switch the language of the content served

Details

Reference
bz30047

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:50 PM
bzimport set Reference to bz30047.

bugzilla wrote:

better:

global $wgLanguageSelectorRequestedLanguage, $wgLanguageNames, $wgLanguageSelectorAdjustContent;

if( isset($wgLanguageSelectorRequestedLanguage) && strlen($wgLanguageSelectorRequestedLanguage)>0){
  if( isset($wgLanguageSelectorAdjustContent) && $wgLanguageSelectorAdjustContent=== LANGUAGE_SELECTOR_ADJUST_CONTENT){
    $langstr="/".$wgLanguageSelectorRequestedLanguage;
    $searchstr="#/(". implode('|',array_keys($wgLanguageNames)) ."$)#";
    if(preg_match($searchstr,$title->mTextform)){
      $title->mTextform =preg_replace($searchstr,$langstr, $title->mTextform);
      $title->mUrlform =preg_replace($searchstr,$langstr, $title->mUrlform);
      $title->mDbkeyform =preg_replace($searchstr,$langstr, $title->mDbkeyform);
      $title->mUserCaseDBKey =preg_replace($searchstr,$langstr, $title->mUserCaseDBKey);
    }else{
      if($_GET['setlang']== $wgLanguageSelectorRequestedLanguage){
        $title->mTextform.=$langstr;
        $title->mUrlform.=$langstr;
        $title->mDbkeyform.=$langstr;
        $title->mUserCaseDBKey.=$langstr;
      }
    }
  }
}
return true;

Any chance you could provide this as a unified diff or similar?

Thanks!

bugzilla wrote:

Patch for adjust Content.

Attached:

IAlex made some comments https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106546#c27940 and I've reverted this fix. Please see if you can address those issues and re-submit the patch.

incarus6 wrote:

This is still an actual problem. There is also no way to change the language settings of the user interface while not logged in.

Those language links on the main page are changing online the contents of the main page.

I think this could be accelerated by putting it into Gerrit as a patch set. (meanwhile the tool of choice for code review)

Good that this report exists because I was going to file it for the same reason.

If you go to mediawiki.org, Commons, or Meta if you change the default English for, say, Italiano the MediaWiki UI will change but the language of the content will stay as is, even if a full Italian version is available.

In the meantime, these homepages contain huge boxes at the bottom linking to all the languages available.

It makes sense to think that a user selecting Italiano wants to see as much content in Italiano by default. Luckily, if the browser is defaulting Italian then luckily the content offered will be Italian as well. Still, I don't see a reason not to default to language X for everything if the user has selected such language. This is what any normal website does.

(In reply to Quim Gil from comment #9)

Good that this report exists because I was going to file it for the same
reason.

If you go to mediawiki.org, Commons, or Meta if you change the default
English for, say, Italiano the MediaWiki UI will change but the language of
the content will stay as is, even if a full Italian version is available.

Quim, none of these wikis has the LanguageSelector extension enabled, they have the UniversalLanguageSelector (+ 1-3 other distinct language selection methods at the same time in Wikidata, Commons and Meta). Translate's Special:MyLanguage already selects target page language based on interface language, so this can be broken down into:

  • automatically redirecting to the translation page in interface language when selecting language with ULS (ULS bug probably not filed);
  • allowing links to keep the content language constant disregarding interface language (e.g. it->it links under en interface): bug 57603;
  • a general solution for content language switch, possibly as part of the compact interlanguage links in sidebar: current [[mw:OPW]] project by Niharika.

(In reply to Nemo from comment #10)

  • automatically redirecting to the translation page in interface language

when selecting language with ULS (ULS bug probably not filed);

Filed now as Bug 61695. Thank you for the clarification and sorry for my mistake.

daniel subscribed.