From a18e7f841a93cadebc20bed642daf5e8059fadd8 Mon Sep 17 00:00:00 2001 From: vinnl Date: Fri, 29 Feb 2008 00:23:08 +0100 Subject: [PATCH] Started on the translation module so I can start off with i18n support. --- TODO | 1 - project/data/config/cache.ini | 8 ++++ project/data/{config.ini => config/general.ini} | 0 project/index.php | 4 ++ project/library/Pivip/Debug.php | 2 +- project/modules/page/Module.php | 1 + .../modules/page/views/{ => scripts}/layout.phtml | 0 project/modules/{page => translate}/Module.php | 53 ++++++++++------------ project/modules/translate/Version.php | 39 ++++++++++++++++ project/modules/translate/config.ini | 0 10 files changed, 77 insertions(+), 31 deletions(-) delete mode 100644 TODO create mode 100644 project/data/config/cache.ini rename project/data/{config.ini => config/general.ini} (100%) rename project/modules/page/views/{ => scripts}/layout.phtml (100%) copy project/modules/{page => translate}/Module.php (57%) create mode 100644 project/modules/translate/Version.php create mode 100644 project/modules/translate/config.ini diff --git a/TODO b/TODO deleted file mode 100644 index c19b7d8..0000000 --- a/TODO +++ /dev/null @@ -1 +0,0 @@ -Move the commented-out meta tags in layout.phtml to a script \ No newline at end of file diff --git a/project/data/config/cache.ini b/project/data/config/cache.ini new file mode 100644 index 0000000..12ddca3 --- /dev/null +++ b/project/data/config/cache.ini @@ -0,0 +1,8 @@ +; Configure caching +; See http://framework.zend.com/manual/en/zend.cache.html + +backend = "File" +cache_root = "./data/cache" + +[backendOptions] +cache_dir = "./data/cache/default" \ No newline at end of file diff --git a/project/data/config.ini b/project/data/config/general.ini similarity index 100% rename from project/data/config.ini rename to project/data/config/general.ini diff --git a/project/index.php b/project/index.php index 1d82fb9..0ece2e2 100644 --- a/project/index.php +++ b/project/index.php @@ -11,6 +11,10 @@ set_include_path('library' require 'Zend/Loader.php'; Zend_Loader::registerAutoload(); +// Load the cache configuration and save it to the registry +$cacheConfig = new Zend_Config_Ini('./data/config/cache.ini'); +Zend_Registry::set('cacheConfig', $cacheConfig); + // Load the modules and run their bootstrap code $modules = new Pivip_Modules(); diff --git a/project/library/Pivip/Debug.php b/project/library/Pivip/Debug.php index 12912a5..f90dc51 100644 --- a/project/library/Pivip/Debug.php +++ b/project/library/Pivip/Debug.php @@ -41,7 +41,7 @@ class Pivip_Debug extends Zend_Debug */ public static function getSetup() { - $configuration = new Zend_Config_Ini('data/config.ini', 'developers'); + $configuration = new Zend_Config_Ini('data/config/general.ini', 'developers'); switch($configuration->setup) { case 'dev': diff --git a/project/modules/page/Module.php b/project/modules/page/Module.php index f69e71e..895fa7f 100644 --- a/project/modules/page/Module.php +++ b/project/modules/page/Module.php @@ -102,5 +102,6 @@ class Page_Module extends Pivip_Module_Abstract 'page' => '' )); $router->addRoute('default', $route); + Zend_Layout::startMvc(array('layoutPath' => 'views/')); } } \ No newline at end of file diff --git a/project/modules/page/views/layout.phtml b/project/modules/page/views/scripts/layout.phtml similarity index 100% rename from project/modules/page/views/layout.phtml rename to project/modules/page/views/scripts/layout.phtml diff --git a/project/modules/page/Module.php b/project/modules/translate/Module.php similarity index 57% copy from project/modules/page/Module.php copy to project/modules/translate/Module.php index f69e71e..9b06279 100644 --- a/project/modules/page/Module.php +++ b/project/modules/translate/Module.php @@ -19,55 +19,46 @@ * * @license http://www.fsf.org/licensing/licenses/info/GPLv2.html GPL v.2 * @category PivipModulesDefault - * @package Module_Page + * @package Module_Translate * @copyright (C) 2008 Vincent Tunru * @author Vincent Tunru */ /** - * Manage the Page module - * - * The Page module handles detemining which modules need to be loaded for each - * page. + * Manage the Translate module * * @see /library/Pivip/Module/Abstract.php */ -class Page_Module extends Pivip_Module_Abstract +class Translate_Module extends Pivip_Module_Abstract { /** * Defines the dependencies * - * Page depends on Pivip + * Translate depends on Pivip */ protected $_dependencies = array('Pivip' => array('max' => '0.0.0dev')); /** * Checks whether this module is already installed * - * In the case of the Page module, "installed" means that the database - * exists. - * - * @return boolean Whether Page is already installed. + * @return boolean Whether Translate is already installed. */ public static function isInstalled() { } /** - * Communicate that Page does not need any configuration - * - * Always returns false since there is nothing to configure for the Page - * module. + * Communicate that Translate needs configuration * - * @return boolean False, since Page does not need to be configured. + * @return boolean True, since Page does not need to be configured. */ public static function needsConfiguring() { - return false; + return true; } /** - * Creates the table in the database + * Install Translate * * @throws Pivip_Install_Exception * @return boolean Whether the installation succeeded @@ -77,7 +68,7 @@ class Page_Module extends Pivip_Module_Abstract } /** - * Remove the table from the database + * Uninstall Translate * * @throws Pivip_Install_Exception * @return boolean Whether uninstallation succeeded @@ -89,18 +80,22 @@ class Page_Module extends Pivip_Module_Abstract /** * Load the module * - * Sets the default route to the Page module. + * Opens the cache for translations, loads the languages. */ public static function bootstrap() { - $frontController = Zend_Controller_Front::getInstance(); - require_once 'plugins/SegmentMapper.php'; - $frontController->registerPlugin(new SegmentMapper()); - $router = $frontController->getRouter(); - $route = new Zend_Controller_Router_Route(':page', - array('module' => 'page', - 'page' => '' - )); - $router->addRoute('default', $route); + $cacheConfig = Zend_Registry::get('cacheConfig'); + $options = $cacheConfig->toArray(); + $frontendOptions = array('automatic_serialization' => true); + $cache = Zend_Cache::factory('Page', + $cacheConfig->backend, + $frontendOptions, + $options['backendOptions']); + Zend_Translate::setCache($cache); + $translate = new Zend_Translate('gettext', 'data/translations', null, + array('scan' + => Zend_Translate::LOCALE_DIRECTORY + )); + Zend_Registry::set('translate', $translate); } } \ No newline at end of file diff --git a/project/modules/translate/Version.php b/project/modules/translate/Version.php new file mode 100644 index 0000000..7ac3f0b --- /dev/null +++ b/project/modules/translate/Version.php @@ -0,0 +1,39 @@ + + */ + +/** + * Get the current version of the Translate module + */ +class Translate_Version extends Pivip_Version_Abstract +{ + /** + * @return string Translate module's current version + */ + public static function getVersion() + { + return '0.0.0dev'; + } +} \ No newline at end of file diff --git a/project/modules/translate/config.ini b/project/modules/translate/config.ini new file mode 100644 index 0000000..e69de29 -- 2.11.4.GIT