Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CS-5775 - handle translations in tpls via CLI #1108

Open
wants to merge 3 commits into
base: v4.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions newscoop/template_engine/classes/CampTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* @version $Revision$
* @link http://www.sourcefabric.org
*/

use Symfony\Component\Finder\Finder;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -70,34 +69,34 @@ public function __construct()
}

// define dynamic uncached block
require_once APPLICATION_PATH . self::PLUGINS . '/block.dynamic.php';
require_once APPLICATION_PATH.self::PLUGINS.'/block.dynamic.php';
$this->registerPlugin('block', 'dynamic', 'smarty_block_dynamic', false);

// define render function
require_once APPLICATION_PATH . self::PLUGINS . '/function.render.php';
require_once APPLICATION_PATH.self::PLUGINS.'/function.render.php';
$this->registerPlugin('function', 'render', 'smarty_function_render', false);

// define translate modifier
require_once APPLICATION_PATH . self::PLUGINS . '/modifier.translate.php';
require_once APPLICATION_PATH.self::PLUGINS.'/modifier.translate.php';
$this->registerPlugin('modifier', 'translate', 'smarty_modifier_translate', false);

$this->left_delimiter = '{{';
$this->right_delimiter = '}}';
$this->auto_literal = false;

$this->cache_dir = APPLICATION_PATH . '/../cache';
$this->compile_dir = APPLICATION_PATH . '/../cache';
$this->cache_dir = APPLICATION_PATH.'/../cache';
$this->compile_dir = APPLICATION_PATH.'/../cache';

$this->plugins_dir = array_merge(
(array) $this->plugins_dir,
array(APPLICATION_PATH . self::PLUGINS),
array(APPLICATION_PATH.self::PLUGINS),
self::getPluginsPluginsDir()
);

$this->setTemplateDir(array(
APPLICATION_PATH . '/../themes/',
APPLICATION_PATH . '/../themes/system_templates/',
APPLICATION_PATH . self::SCRIPTS,
APPLICATION_PATH.'/../themes/',
APPLICATION_PATH.'/../themes/system_templates/',
APPLICATION_PATH.self::SCRIPTS,
));

$this->assign('view', \Zend_Registry::get('container')->get('view'));
Expand All @@ -109,7 +108,9 @@ public function __construct()
'description' => $preferencesService->SiteMetaDescription,
));

$this->getTemplateTranslationsFiles();
if (php_sapi_name() !== 'cli') {
$this->getTemplateTranslationsFiles();
}
}

/**
Expand All @@ -119,12 +120,10 @@ public function __construct()
*/
private function getTemplateTranslationsFiles()
{
$request = \Zend_Registry::get('container')->getService('request');
$cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
$translator = \Zend_Registry::get('container')->getService('translator');
$themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
$locale = $request->getLocale();

$locale = $translator->getLocale();
$cacheKey = $cacheService->getCacheKey(array('templates_translations', $themesService->getThemePath(), $locale), 'templates_translations');
$templateTranslations = array();
if ($cacheService->contains($cacheKey)) {
Expand All @@ -137,7 +136,7 @@ private function getTemplateTranslationsFiles()
}

$filesystem = new Filesystem();
$dir = __DIR__.'/../../themes/' . $themesService->getThemePath() . 'translations';
$dir = __DIR__.'/../../themes/'.$themesService->getThemePath().'translations';
if ($filesystem->exists($dir)) {
$finder = new Finder();
$translator->addLoader('yaml', new YamlFileLoader());
Expand Down Expand Up @@ -167,19 +166,19 @@ public static function getPluginsPluginsDir()
$dirs = array();
foreach ($availablePlugins as $plugin) {
$pluginPath = explode('\\', $plugin);
$directoryPath = realpath(__DIR__ . '/../../plugins/'.$pluginPath[0].'/'.$pluginPath[1].'/Resources/smartyPlugins');
$directoryPath = realpath(__DIR__.'/../../plugins/'.$pluginPath[0].'/'.$pluginPath[1].'/Resources/smartyPlugins');
if ($directoryPath) {
$dirs[] = $directoryPath;
}
}

//legacy plugins
foreach (CampPlugin::GetEnabled() as $CampPlugin) {
$dirs[] = CS_PATH_SITE . "/{$CampPlugin->getBasePath()}/smarty_camp_plugins";
$dirs[] = CS_PATH_SITE."/{$CampPlugin->getBasePath()}/smarty_camp_plugins";
}

//comunity ticker
$dirs[] = __DIR__ . '/../../src/Newscoop/CommunityTickerBundle/Resources/smartyPlugins';
$dirs[] = __DIR__.'/../../src/Newscoop/CommunityTickerBundle/Resources/smartyPlugins';

return $dirs;
}
Expand Down