diff options
| author | 2014-06-15 17:49:23 +0200 | |
|---|---|---|
| committer | 2014-06-15 17:49:23 +0200 | |
| commit | 09602acc5f754c3e814b4b7de9d9d4d283ed45ff (patch) | |
| tree | 5c364497d2769f171e9e90b4d99afbe496965528 | |
| parent | 81e4638f5a7b80d8c8339b1e32644fd234935f89 (diff) | |
Add two wrappers (_t() and _i())
- _t() is a wrapper for Minz_Translate::t()
- Improve coding style of Translate.php
- _i() is a wrapper for FreshRSS::icon()
- queries.phtml shows how they work
- It is a lot easier to read files with these functions :)
| -rw-r--r-- | app/Models/Themes.php | 4 | ||||
| -rw-r--r-- | app/views/configure/queries.phtml | 28 | ||||
| -rw-r--r-- | lib/Minz/Translate.php | 34 |
3 files changed, 39 insertions, 27 deletions
diff --git a/app/Models/Themes.php b/app/Models/Themes.php index 2e2c3f9cd..b4e8f4ccc 100644 --- a/app/Models/Themes.php +++ b/app/Models/Themes.php @@ -110,3 +110,7 @@ class FreshRSS_Themes extends Minz_Model { '<img class="icon" src="' . Minz_Url::display($url) . '" alt="' . $alts[$name] . '" />'; } } + +function _i($icon, $url_only = false) { + return FreshRSS_Themes::icon($icon, $url_only); +} diff --git a/app/views/configure/queries.phtml b/app/views/configure/queries.phtml index d0aec687b..2895f584c 100644 --- a/app/views/configure/queries.phtml +++ b/app/views/configure/queries.phtml @@ -1,15 +1,15 @@ <?php $this->partial('aside_configure'); ?> <div class="post"> - <a href="<?php echo _url('index', 'index'); ?>"><?php echo Minz_Translate::t('back_to_rss_feeds'); ?></a> + <a href="<?php echo _url('index', 'index'); ?>"><?php echo _t('back_to_rss_feeds'); ?></a> <form method="post" action="<?php echo _url('configure', 'queries'); ?>"> - <legend><?php echo Minz_Translate::t('queries'); ?></legend> + <legend><?php echo _t('queries'); ?></legend> <?php foreach ($this->conf->queries as $key => $query) { ?> <div class="form-group" id="query-group-<?php echo $key; ?>"> <label class="group-name" for="queries_<?php echo $key; ?>_name"> - <?php echo Minz_Translate::t('query_number', $key + 1); ?> + <?php echo _t('query_number', $key + 1); ?> </label> <div class="group-controls"> @@ -27,11 +27,11 @@ /> <a class="btn" href="<?php echo $query['url']; ?>"> - <?php echo FreshRSS_Themes::icon('link'); ?> + <?php echo _i('link'); ?> </a> <a class="btn btn-attention remove" href="#" data-remove="query-group-<?php echo $key; ?>"> - <?php echo FreshRSS_Themes::icon('close'); ?> + <?php echo _i('close'); ?> </a> </div> @@ -46,27 +46,27 @@ <?php if ($exist === 0) { ?> <div class="alert alert-warn"> - <div class="alert-head"><?php echo Minz_Translate::t('no_query_filter'); ?></div> + <div class="alert-head"><?php echo _t('no_query_filter'); ?></div> </div> <?php } else { ?> <div class="alert alert-success"> - <div class="alert-head"><?php echo Minz_Translate::t('query_filter'); ?></div> + <div class="alert-head"><?php echo _t('query_filter'); ?></div> <ul> <?php if (isset($query['search'])) { $exist = true; ?> - <li class="item"><?php echo Minz_Translate::t('query_search', $query['search']); ?></li> + <li class="item"><?php echo _t('query_search', $query['search']); ?></li> <?php } ?> <?php if (isset($query['state'])) { $exist = true; ?> - <li class="item"><?php echo Minz_Translate::t('query_state_' . $query['state']); ?></li> + <li class="item"><?php echo _t('query_state_' . $query['state']); ?></li> <?php } ?> <?php if (isset($query['order'])) { $exist = true; ?> - <li class="item"><?php echo Minz_Translate::t('query_order_' . strtolower($query['order'])); ?></li> + <li class="item"><?php echo _t('query_order_' . strtolower($query['order'])); ?></li> <?php } ?> <?php if (isset($query['get'])) { $exist = true; ?> - <li class="item"><?php echo Minz_Translate::t('query_get_' . $this->query_get[$key]['type'], $this->query_get[$key]['name']); ?></li> + <li class="item"><?php echo _t('query_get_' . $this->query_get[$key]['type'], $this->query_get[$key]['name']); ?></li> <?php } ?> </ul> </div> @@ -78,12 +78,12 @@ <?php if (count($this->conf->queries) > 0) { ?> <div class="form-group form-actions"> <div class="group-controls"> - <button type="submit" class="btn btn-important"><?php echo Minz_Translate::t ('save'); ?></button> - <button type="reset" class="btn"><?php echo Minz_Translate::t ('cancel'); ?></button> + <button type="submit" class="btn btn-important"><?php echo _t('save'); ?></button> + <button type="reset" class="btn"><?php echo _t('cancel'); ?></button> </div> </div> <?php } else { ?> - <p class="alert alert-warn"><span class="alert-head"><?php echo Minz_Translate::t ('damn'); ?></span> <?php echo Minz_Translate::t('no_query'); ?></p> + <p class="alert alert-warn"><span class="alert-head"><?php echo _t('damn'); ?></span> <?php echo _t('no_query'); ?></p> <?php } ?> </form> diff --git a/lib/Minz/Translate.php b/lib/Minz/Translate.php index e14f783f7..df48350e9 100644 --- a/lib/Minz/Translate.php +++ b/lib/Minz/Translate.php @@ -18,28 +18,28 @@ class Minz_Translate { * $translates est le tableau de correspondance * $key => $traduction */ - private static $translates = array (); + private static $translates = array(); /** * Inclus le fichier de langue qui va bien * l'enregistre dans $translates */ - public static function init () { - $l = Minz_Configuration::language (); - self::$language = Minz_Session::param ('language', $l); + public static function init() { + $l = Minz_Configuration::language(); + self::$language = Minz_Session::param('language', $l); $l_path = APP_PATH . '/i18n/' . self::$language . '.php'; - if (file_exists ($l_path)) { - self::$translates = include ($l_path); + if (file_exists($l_path)) { + self::$translates = include($l_path); } } /** * Alias de init */ - public static function reset () { - self::init (); + public static function reset() { + self::init(); } /** @@ -48,24 +48,32 @@ class Minz_Translate { * @return la valeur correspondante à la clé * > si non présente dans le tableau, on retourne la clé elle-même */ - public static function t ($key) { + public static function t($key) { $translate = $key; - if (isset (self::$translates[$key])) { + if (isset(self::$translates[$key])) { $translate = self::$translates[$key]; } - $args = func_get_args (); + $args = func_get_args(); unset($args[0]); - return vsprintf ($translate, $args); + return vsprintf($translate, $args); } /** * Retourne la langue utilisée actuellement * @return la langue */ - public static function language () { + public static function language() { return self::$language; } } + +function _t($key) { + $args = func_get_args(); + unset($args[0]); + array_unshift($args, $key); + + return call_user_func_array("Minz_Translate::t", $args); +} |
