Esempio n. 1
0
/**
 * Translate text (simple form) with a context.
 *
 * @param string $context A context, useful for translators to better understand the meaning of the text to be translated.
 * @param string $text    The text to be translated.
 * @param        mixed    ... Unlimited optional number of arguments: if specified they'll be used for printf.
 *
 * @return string Returns the translated text.
 *
 * @example tc('Recipient', 'To %s') will return translation for 'To %s' (example for Italian 'A %s').
 * @example tc('End date', 'To %s') will return translation for 'To %s' (example for Italian 'Fino al %s').
 * @example tc('Recipient', 'To %s', 'John') will return translation for 'To %s' (example: 'A %s'), using 'John' for printf (so the final result will be 'A John' for Italian).
 * @example tc('End date', 'To %s', '01/01/2000') will return translation for 'To %s' (example: 'Fino al %s'), using '01/01/2000' for printf (so the final result will be 'Fino al 01/01/2000' for Italian).
 */
function tc($context, $text)
{
    $loc = Localization::getInstance();
    $adapter = $loc->getActiveTranslatorAdapter();
    $args = func_get_args();
    switch (count($args)) {
        case 2:
            return $adapter->translateContext($context, $text);
        case 3:
            return $adapter->translateContext($context, $text, $args[2]);
        case 4:
            return $adapter->translateContext($context, $text, $args[2], $args[3]);
        case 5:
            return $adapter->translateContext($context, $text, $args[2], $args[3], $args[4]);
        default:
            return call_user_func_array(array($adapter, 'translateContext'), $args);
    }
}
Esempio n. 2
0
 /**
  * Initialize localization.
  */
 private function setSystemLocale()
 {
     $u = new User();
     $lan = $u->getUserLanguageToDisplay();
     $loc = Localization::getInstance();
     $loc->setContextLocale('ui', $lan);
 }
Esempio n. 3
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     if (!$c) {
         $c = Page::getCurrentPage();
     }
     $app = Facade::getFacadeApplication();
     // don't translate dashboard pages
     $dh = $app->make('helper/concrete/dashboard');
     if ($dh->inDashboard($c)) {
         return;
     }
     $ms = Section::getBySectionOfSite($c);
     if (!is_object($ms)) {
         $ms = static::getPreferredSection();
     }
     if (!$ms) {
         return;
     }
     $locale = $ms->getLocale();
     if ($locale) {
         $app->make('session')->set('multilingual_default_locale', $locale);
         $loc = Localization::getInstance();
         $loc->setContextLocale('site', $locale);
     }
 }
Esempio n. 4
0
 public function renderViewContents($scopeItems)
 {
     extract($scopeItems);
     if (!$this->outputContent) {
         ob_start();
         include $this->template;
         $this->outputContent = ob_get_contents();
         ob_end_clean();
     }
     // The translatable texts in the block header/footer need to be printed
     // out in the system language.
     $loc = Localization::getInstance();
     $loc->pushActiveContext('ui');
     if ($this->blockViewHeaderFile) {
         include $this->blockViewHeaderFile;
     }
     $this->controller->registerViewAssets($this->outputContent);
     $this->onBeforeGetContents();
     echo $this->outputContent;
     $this->onAfterGetContents();
     if ($this->blockViewFooterFile) {
         include $this->blockViewFooterFile;
     }
     $loc->popActiveContext();
 }
Esempio n. 5
0
 /**
  * Export all the translations associates to every trees.
  *
  * @return Translations
  */
 public static function exportTranslations()
 {
     $translations = new Translations();
     $loc = Localization::getInstance();
     $loc->pushActiveContext('system');
     try {
         $app = Application::getFacadeApplication();
         $db = $app->make('database')->connection();
         $r = $db->executeQuery('select treeID from Trees order by treeID asc');
         while ($row = $r->fetch()) {
             try {
                 $tree = static::getByID($row['treeID']);
             } catch (Exception $x) {
                 $tree = null;
             }
             if (isset($tree)) {
                 /* @var $tree Tree */
                 $treeName = $tree->getTreeName();
                 if (is_string($treeName) && $treeName !== '') {
                     $translations->insert('TreeName', $treeName);
                 }
                 $rootNode = $tree->getRootTreeNodeObject();
                 /* @var $rootNode TreeNode */
                 if (isset($rootNode)) {
                     $rootNode->exportTranslations($translations);
                 }
             }
         }
     } catch (Exception $x) {
         $loc->popActiveContext();
         throw $x;
     }
     $loc->popActiveContext();
     return $translations;
 }
Esempio n. 6
0
 /**
  * Run startup and localization events on any installed packages.
  */
 public function setupPackages()
 {
     $checkAfterStart = false;
     $config = $this['config'];
     $loc = Localization::getInstance();
     $entityManager = $this['Doctrine\\ORM\\EntityManager'];
     $configUpdater = new EntityManagerConfigUpdater($entityManager);
     foreach ($this->packages as $pkg) {
         if ($config->get('concrete.updates.enable_auto_update_packages')) {
             $dbPkg = \Package::getByHandle($pkg->getPackageHandle());
             $pkgInstalledVersion = $dbPkg->getPackageVersion();
             $pkgFileVersion = $pkg->getPackageVersion();
             if (version_compare($pkgFileVersion, $pkgInstalledVersion, '>')) {
                 $loc->pushActiveContext('system');
                 $dbPkg->upgradeCoreData();
                 $dbPkg->upgrade();
                 $loc->popActiveContext();
             }
         }
         $service = $this->make('Concrete\\Core\\Package\\PackageService');
         $service->setupLocalization($pkg);
         if (method_exists($pkg, 'on_start')) {
             $pkg->on_start();
         }
         $service->bootPackageEntityManager($pkg);
         if (method_exists($pkg, 'on_after_packages_start')) {
             $checkAfterStart = true;
         }
     }
     $config->set('app.bootstrap.packages_loaded', true);
     // After package initialization, the translations adapters need to be
     // reinitialized when accessed the next time because new translations
     // are now available.
     $loc->removeLoadedTranslatorAdapters();
     if ($checkAfterStart) {
         foreach ($this->packages as $pkg) {
             if (method_exists($pkg, 'on_after_packages_start')) {
                 $pkg->on_after_packages_start();
             }
         }
     }
 }
 public static function getTranslate()
 {
     $loc = Localization::getInstance();
     return $loc->getActiveTranslateObject();
 }
Esempio n. 8
0
 /**
  * displays the Area in the page
  * ex: $a = new Area('Main'); $a->display($c);.
  *
  * @param Page $c
  * @param Block[] $alternateBlockArray optional array of blocks to render instead of default behavior
  *
  * @return bool
  */
 public function display($c = false, $alternateBlockArray = null)
 {
     if (!$c) {
         $c = Page::getCurrentPage();
     }
     $v = View::getRequestInstance();
     if (!is_object($c) || $c->isError()) {
         return false;
     }
     $this->load($c);
     $ap = new Permissions($this);
     if (!$ap->canViewArea()) {
         return false;
     }
     $blocksToDisplay = $alternateBlockArray ? $alternateBlockArray : $this->getAreaBlocksArray();
     $u = new User();
     // The translatable texts in the area header/footer need to be printed
     // out in the system language.
     $loc = Localization::getInstance();
     // now, we iterate through these block groups (which are actually arrays of block objects), and display them on the page
     $loc->pushActiveContext('ui');
     if ($this->showControls && $c->isEditMode() && $ap->canViewAreaControls()) {
         View::element('block_area_header', array('a' => $this));
     } else {
         View::element('block_area_header_view', array('a' => $this));
     }
     $loc->popActiveContext();
     foreach ($blocksToDisplay as $b) {
         $bv = new BlockView($b);
         $bv->setAreaObject($this);
         $p = new Permissions($b);
         if ($p->canViewBlock()) {
             if (!$c->isEditMode()) {
                 echo $this->enclosingStart;
             }
             $bv->render('view');
             if (!$c->isEditMode()) {
                 echo $this->enclosingEnd;
             }
         }
     }
     $loc->pushActiveContext('ui');
     if ($this->showControls && $c->isEditMode() && $ap->canViewAreaControls()) {
         View::element('block_area_footer', array('a' => $this));
     } else {
         View::element('block_area_footer_view', array('a' => $this));
     }
     $loc->popActiveContext();
 }