Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: anwiki/_override/contentclasses/contentclass_menu/contentclass_menu.tpl.php

Issue 9148089: Less hacky implementation of the language selection (Closed)
Patch Set: Created Jan. 9, 2013, 1:15 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: anwiki/_override/contentclasses/contentclass_menu/contentclass_menu.tpl.php
===================================================================
--- a/anwiki/_override/contentclasses/contentclass_menu/contentclass_menu.tpl.php
+++ b/anwiki/_override/contentclasses/contentclass_menu/contentclass_menu.tpl.php
@@ -29,28 +29,113 @@ EOF;
<button id="search-button" type="submit">$sTitle</button>
</label>
</form>
</li>
EOF;
return $HTML;
}
+ function renderLanguages()
+ {
+ $languages = $this->getLanguages($aoTranslations);
+ if (count($languages) == 0)
+ return "";
+
+ $currentLanguage = array_shift($languages);
+ $currentLang = $currentLanguage['lang'];
+ $currentText = $currentLanguage['text'];
+
+ $HTML = <<<EOF
+
+<li id="language">
+ <div id="current-language">
+ <div id="flag-$currentLang" class="flag sprite"></div><span>$currentText</span>
+ <span id="language-arrow" class="sprite"></span>
+ </div>
+ <ul id="language-selector">
+EOF;
+
+ foreach ($languages as $language)
+ {
+ $url = $language['url'];
+ $linkStyle = $language['linkStyle'];
+ $lang = $language['lang'];
+ $text = $language['text'];
+
+ # Note: The space before URL is required because otherwise Anwiki will
+ # automatically replace the URL based on current language.
+ $HTML .= <<<EOF
+
+ <li class="language-entry"><a href=" $url"$linkStyle><div id="flag-$lang" class="flag sprite"></div>$text</a></li>
+EOF;
+ }
+
+ $HTML .= <<<EOF
+
+ </ul>
+</li>
+EOF;
+ return $HTML;
+ }
+
+ private function getLanguages()
+ {
+ $languages = array();
+
+ $currentPageName = AnwActionPage::getCurrentPageName();
+ if (!AnwPage::isValidPageName($currentPageName))
+ return $languages;
+
+ $currentPage = new AnwPageByName($currentPageName);
+ $pages = $currentPage->getPageGroup()->getPages();
+ $translationThreshold = AnwComponent::globalCfgViewUntranslatedMinpercent();
+ foreach ($pages as $page)
+ {
+ if ($page->isActionAllowed('view'))
+ {
+ $current = ($page->getName() == $currentPageName);
+ $online = ($page->getTranslatedPercent() >= $translationThreshold);
+ $linkStyle = ($online ? '' : ' style="text-decoration:line-through;"');
+ $lang = $this->xQuote($page->getLang());
+ $text = $this->xText(self::g_('lang_' . $lang, array(),
+ AnwAction::getActionLang()));
+ $entry = array("lang" => $lang, "linkStyle" => $linkStyle,
+ "text" => $text);
+ if ($current)
+ array_unshift($languages, $entry);
+ else
+ {
+ $params = $_GET;
+ unset($params[AnwActionPage::GET_PAGENAME]); //avoid loop
+ unset($params['browser']);
+ $url = AnwUtils::link($page, "view", $params);
+ $entry['url'] = $this->xQuote($url);
+ array_push($languages, $entry);
+ }
+ }
+ }
+
+ return $languages;
+ }
+
function mainItem($sTitle, $sUrl, $sTarget, $sRenderedSubItems=false)
{
if ($this->firstItem)
{
$classAttribute = ' class="first"';
$this->firstItem = false;
}
else
$classAttribute = '';
if ($sUrl == "/search/")
return $this->renderSearch($sTitle, $classAttribute);
+ else if ($sUrl == "/languages/")
+ return $this->renderLanguages();
# Anything with a link relative to site root must be in English
$sHrefLang = (preg_match('!^/!', $sUrl) ? ' hreflang="en"' : '');
$HTML = <<<EOF
<li$classAttribute><a href="$sUrl"$sHrefLang>$sTitle</a></li>
EOF;

Powered by Google App Engine
This is Rietveld