[Search wiki] Non-english mini-articles

Balinny balinny at gmail.com
Fri Jan 11 13:22:42 UTC 2008


jer wrote:
> Maybe this has been resolved already and I'm just unaware, but how  
> exactly should the search client (the html/js at re.search.wikia.com)  
> detect the browser's language and pull in the appropriate language  
> miniarticle?  I'd be happy to code something in the JavaScript if  
> anyone had pointers on the right thing to do?
>   
You'd need to pull it from the accept-language header. but i don't  have 
any idea on how to
do it with javascript.

How is wfGetArticleJSON() implemented?


I'd do it there, with something like:
function wfGetArticleByUserLanguageJSON($title, $lang)  {
if (!is_set($lang))
  $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$Languages = ParseAcceptLanguages($lang);

foreach $Languages as $lng {
  $TitleObj = Title::newFromText("$title/$lng");
  if (page_exists)
      return page_content . '<p style="text-align: right"><a href="' . 
Title::newFromText("Special:Prefixindex")->getFullURL("namespace=" . 
$TitleObj->getNamespace() . "&from=" . $title) . '">' . 
wfMsg('view-in-other-languages') . "</a></p>"; //FIXME: wfMsg is not 
aware of the $lang supplied here...
}

//Do the same as current wfGetArticleJSON()
$TitleObj = Title::newFromText("$title");
  if (page_exists)
     return Content;
}
$wgAjaxExportList[] = 'wfGetArticleByUserLanguageJSON';

Where ParseAcceptLanguages($str); parses an Accept Language header and 
returns an array of the
user accepted languages sorted by priority (;q=n), removes variants when 
needed, etc.




More information about the SearchWiki mailing list