Last modified: 2014-02-20 19:04:17 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T32047, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 30047 - Language selection does not change the Content-language
Language selection does not change the Content-language
Status: REOPENED
Product: MediaWiki extensions
Classification: Unclassified
LanguageSelector (Other open bugs)
unspecified
All All
: Normal normal (vote)
: ---
Assigned To: Daniel Kinzler
: i18n, patch, patch-reviewed
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-25 10:56 UTC by Harald Stowasser
Modified: 2014-02-20 19:04 UTC (History)
10 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Patch for adjust Content. (1.84 KB, patch)
2011-07-26 06:50 UTC, Harald Stowasser
Details

Description Harald Stowasser 2011-07-25 10:56:21 UTC
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?
Comment 1 Harald Stowasser 2011-07-25 13:47:32 UTC
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;
Comment 2 Sam Reed (reedy) 2011-07-25 13:52:08 UTC
Any chance you could provide this as a unified diff or similar?

Thanks!
Comment 3 Harald Stowasser 2011-07-26 06:50:19 UTC
Created attachment 8823 [details]
Patch for adjust Content.
Comment 4 Mark A. Hershberger 2011-12-18 01:49:41 UTC
r106546
Comment 5 Mark A. Hershberger 2011-12-27 13:48:29 UTC
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.
Comment 6 Incarus 2012-12-18 19:15:30 UTC
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.
Comment 7 Incarus 2012-12-18 19:17:09 UTC
-online / +only
Comment 8 Daniel Zahn 2012-12-18 19:39:13 UTC
I think this could be accelerated by putting it into Gerrit as a patch set. (meanwhile the tool of choice for code review)
Comment 9 Quim Gil 2014-01-09 22:05:03 UTC
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.
Comment 10 Nemo 2014-02-20 18:24:07 UTC
(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.
Comment 11 Quim Gil 2014-02-20 19:04:17 UTC
(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.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links