Пример #1
0
 static function t_($id, $params, $sPrefix, $sLang = false, $sValueIfNotFound = false)
 {
     if ($sLang == false) {
         if (self::isLocalTranslation($id)) {
             $sLang = AnwAction::getActionLang();
         } else {
             $sLang = AnwCurrentSession::getLang();
         }
     }
     $translation = "";
     if (!isset(self::$translations[$sLang][$sPrefix][$id])) {
         //translation is not yet loaded, search in queued translations files
         AnwDebug::log("(Anwi18n) looking for: '" . $id . "' (" . $sLang . ")");
         if (count(@self::$asQueuedTranslationNames[$sPrefix]) > 0) {
             //we have unloaded translations, load it now
             foreach (self::$asQueuedTranslationNames[$sPrefix] as $sTranslationName => $null) {
                 unset(self::$asQueuedTranslationNames[$sPrefix][$sTranslationName]);
                 //avoid recursive loops
                 self::loadTranslationsFromLang($sTranslationName, $sLang);
             }
         }
     }
     if (!isset(self::$translations[$sLang][$sPrefix][$id])) {
         if (count(@self::$aaLoadedTranslationNames[$sPrefix]) > 0) {
             //make sure we loaded corresponding translation files in the requested language
             foreach (self::$aaLoadedTranslationNames[$sPrefix] as $sTranslationName => $null) {
                 if (!isset(self::$aaLoadedTranslationNames[$sPrefix][$sTranslationName][$sLang])) {
                     self::loadTranslationsFromLang($sTranslationName, $sLang);
                 }
             }
         }
     }
     if (isset(self::$translations[$sLang][$sPrefix][$id])) {
         //translation is already loaded
         $translation = self::$translations[$sLang][$sPrefix][$id];
         //parse parameters: parameters names start with % and end with %
         foreach ($params as $find => $replace) {
             $find = '%' . $find . '%';
             $translation = str_replace($find, $replace, $translation);
         }
     } else {
         if ($sLang != self::LANG_DEFAULT) {
             //try in default language
             return self::t_($id, $params, $sPrefix, self::LANG_DEFAULT, $sValueIfNotFound);
         }
         $translation = $sValueIfNotFound === false ? '#' . $id . '#' : $sValueIfNotFound;
         AnwDebug::log("! Missing translation : {$id}");
         //print $sPrefix.'!'.$id.'!';print_r(self::$translations);exit;
     }
     return $translation;
 }
Пример #2
0
 protected function getMenuPage()
 {
     $oPage = null;
     try {
         $sMenuPageName = $this->getMenuPageName();
         $sActionLang = AnwAction::getActionLang();
         $oPage = AnwStorage::getPageByName($sMenuPageName, false, false, $sActionLang);
         // we don't check ACLs for better performances...
         // load translation if available
         if ($oPage->getLang() != $sActionLang) {
             $oPage = $oPage->getPageGroup()->getPreferedPage($sActionLang);
         }
     } catch (AnwException $e) {
     }
     return $oPage;
 }
Пример #3
0
 protected function showCurrentPage()
 {
     //prepare content for display
     try {
         $oOutputHtml = $this->getoPage()->toHtml();
     } catch (AnwException $e) {
         $oOutputHtml = new AnwOutputHtml($this->getoPage());
         $oOutputHtml->setBody(self::g_("err_rendercontent"), false);
         AnwDebug::reportError($e);
     }
     $this->head($oOutputHtml->runHead());
     $this->title = $oOutputHtml->runTitle();
     $sBody = $oOutputHtml->runBody();
     //if the translation is not complete, display a notice
     if (!$this->getoPage()->isTranslated() && $this->getoPage()->isActionAllowed('translate')) {
         $sNotice = $this->t_("local_notice_incomplete", array("lnkopen" => '<a href="' . AnwUtils::link($this->getoPage(), "translate") . '">', "lnkclose" => '</a>'));
         $this->out .= $this->tpl()->drawNotice($sNotice);
     }
     //page translations
     $aoTranslations = array();
     $aoPages = $this->getoPage()->getPageGroup()->getPages();
     foreach ($aoPages as $oPage) {
         if ($oPage->isActionAllowed('view')) {
             $bCurrent = $oPage->getName() == $this->getoPage()->getName();
             $bTranslatedPercentEnough = $oPage->getTranslatedPercent() >= self::globalCfgViewUntranslatedMinpercent() ? true : false;
             $aoTranslations[] = array('current' => $bCurrent, 'page' => $oPage, 'online' => $bTranslatedPercentEnough);
         }
     }
     //display page content
     $this->out .= $this->tpl()->viewPage(self::g_("local_html_dir", array(), AnwAction::getActionLang()), AnwUtils::cssViewContent($this->getoPage()), $this->title, $sBody, str_replace(',', ' ', Anwi18n::dateTime($this->getoPage()->getTime(), AnwAction::getActionLang())), $aoTranslations);
 }
Пример #4
0
 function genTranslateForm_onContentFieldValue($oContentField, $oXmlValue, $sInputName)
 {
     $nTranslatableFields = 0;
     //$this->generateTranslatableFields($oNodeRoot, $sFieldName, &$sTranslatableContent, &$nTranslatableFields);
     $fOnTextValue = "genTranslatableField_onTextValue";
     $fBeforeChilds = "genTranslatableField_beforeChilds";
     $fAfterChilds = "genTranslatableField_afterChilds";
     $fOnUntranslatableNode = "genTranslatableField_onUntranslatableNode";
     //&$sTranslatableContent, &$nTranslatableFields
     $this->genTranslatableField_html = "";
     AnwUtils::runCallbacksOnTranslatableValue($this, $oXmlValue, $sInputName, $fOnTextValue, $fBeforeChilds, $fAfterChilds, $fOnUntranslatableNode);
     //print htmlentities($sTranslatableContent);
     //only edit ContentFields which have translatable content
     if ($this->genTranslatableField_html != "") {
         $this->genTranslatableField_html = $this->simplifyHtmlForTranslation($this->genTranslatableField_html);
         $sContentHtmlDir = self::g_("local_html_dir", array(), AnwAction::getActionLang());
         $this->genTranslateForm_html .= $this->tpl()->translateContentField($sContentHtmlDir, $oContentField->getFieldLabel(), $this->genTranslatableField_html);
     }
 }