Changeset 5167


Ignore:
Timestamp:
03/17/10 20:46:45 (10 years ago)
Author:
nikrou
Message:

Feature 1451 :

  • improve speed to generate pages when locales is not present on system
  • default domain in now piwigo
  • each plugin can have is own domain ({'...'|@translate:my_plugin})
Location:
branches/gettext
Files:
2 added
7 deleted
15 edited
8 moved

Legend:

Unmodified
Added
Removed
  • branches/gettext/include/common.inc.php

    r5138 r5167  
    148148load_language('local.lang', '', array('no_fallback'=>true) ); 
    149149 
     150bind_pwg_textdomain(); 
     151 
    150152// only now we can set the localized username of the guest user (and not in 
    151153// include/user.inc.php) 
  • branches/gettext/include/constants.php

    r5158 r5167  
    9898if (!defined('OLD_PERMALINKS_TABLE')) 
    9999  define('OLD_PERMALINKS_TABLE', $prefixeTable.'old_permalinks'); 
     100if (!defined('THEMES_TABLE')) 
     101  define('THEMES_TABLE', $prefixeTable.'themes'); 
    100102 
    101103?> 
  • branches/gettext/include/functions.inc.php

    r5138 r5167  
    542542    // we ask midday because Windows think it's prior to midnight with a 
    543543    // zero and refuse to work 
    544     $formated_date.= $lang['day'][date('w', mktime(12,0,0,$ymdhms[1],$ymdhms[2],$ymdhms[0]))]; 
     544    $formated_date.= l10n(date('l', mktime(12,0,0,$ymdhms[1],$ymdhms[2],$ymdhms[0]))); 
    545545  } 
    546546  $formated_date.= ' '.$ymdhms[2]; 
    547   $formated_date.= ' '.$lang['month'][(int)$ymdhms[1]]; 
     547  $formated_date.= ' '.l10n(date('F', mktime(12,0,0,$ymdhms[1],$ymdhms[2],$ymdhms[0]))); 
    548548  $formated_date.= ' '.$ymdhms[0]; 
    549549  if ($show_time and count($ymdhms)>=5 ) 
     
    714714function get_pwg_themes() 
    715715{ 
    716   global $conf; 
    717716  $themes = array(); 
    718717 
    719   $template_dir = PHPWG_ROOT_PATH.'themes'; 
    720  
    721   foreach (get_dirs($template_dir) as $theme) 
    722   { 
    723     if ( $theme != 'default' ) 
    724           { 
    725       array_push($themes, $theme); 
    726           } 
     718  $query = ' 
     719SELECT 
     720    id, 
     721    name 
     722  FROM '.THEMES_TABLE.' 
     723  ORDER BY name ASC 
     724;'; 
     725  $result = pwg_query($query); 
     726  while ($row = pwg_db_fetch_assoc($result)) 
     727  { 
     728    $themes[ $row['id'] ] = $row['name']; 
    727729  } 
    728730 
    729731  // plugins want remove some themes based on user status maybe? 
    730732  $themes = trigger_event('get_pwg_themes', $themes); 
     733   
    731734  return $themes; 
    732735} 
     
    862865 
    863866/** 
     867 * bind piwigo textdomain  
     868 */ 
     869function bind_pwg_textdomain()  
     870{ 
     871  global $user; 
     872 
     873  if (empty($user['language'])) 
     874  { 
     875    $locale = $GLOBALS['language']; 
     876  } 
     877  else 
     878  { 
     879    $locale = $user['language']; 
     880  } 
     881 
     882  $locale .= '.UTF-8'; 
     883  putenv('LC_ALL='.$locale); 
     884  T_setlocale(LC_ALL, $locale); 
     885 
     886  T_bindtextdomain('piwigo', './language'); 
     887} 
     888 
     889/** 
    864890 * returns the corresponding value from $lang if existing. Else, the key is 
    865891 * returned 
    866892 * 
    867893 * @param string key 
     894 * @param string textdomain domain where to find keys 
    868895 * @return string 
    869896 */ 
    870 function l10n($key, $textdomain='messages') 
    871 { 
    872   global $user; 
    873  
    874   if (empty($user['language'])) 
    875   { 
    876     $locale = $GLOBALS['language']; 
    877   }  
    878   else  
    879   { 
    880     $locale = $user['language']; 
    881   } 
    882  
    883   T_setlocale(LC_ALL, $locale.'.UTF-8'); 
    884  
    885   // Specify location of translation tables 
    886   T_bindtextdomain($textdomain, "./language"); 
    887  
    888   // Choose domain 
     897function l10n($key, $textdomain='piwigo') 
     898{ 
     899  T_bind_textdomain_codeset($textdomain, 'UTF-8'); 
    889900  T_textdomain($textdomain); 
    890    
     901  
    891902  return T_gettext($key); 
    892903} 
     
    899910 * @param plural string key 
    900911 * @param decimal value 
     912 * @param textdomain string value 
    901913 * @return string 
    902914 */ 
    903915function l10n_dec($singular_fmt_key, $plural_fmt_key,  
    904                   $decimal, $textdomain='messages') 
    905 { 
    906   global $user; 
    907  
    908   if (empty($user['language'])) 
    909   { 
    910     $locale = $GLOBALS['language']; 
    911   }  
    912   else  
    913   { 
    914     $locale = $user['language']; 
    915   } 
    916  
    917   T_setlocale(LC_ALL, $locale.'.UTF-8'); 
    918  
    919   // Specify location of translation tables 
    920   T_bindtextdomain($textdomain, "./language"); 
    921  
    922   // Choose domain 
     916                  $decimal, $textdomain='piwigo') 
     917{ 
     918  T_bind_textdomain_codeset($textdomain, 'UTF-8'); 
    923919  T_textdomain($textdomain); 
    924920 
  • branches/gettext/include/template.class.php

    r5126 r5167  
    6767 
    6868    $this->smarty->assign_by_ref( 'pwg', new PwgTemplateAdapter() ); 
    69     $this->smarty->register_modifier( 'translate', array('Template', 'mod_translate') ); 
     69    $this->smarty->register_modifier( 'translate', array(&$this, 'mod_translate') ); 
    7070    $this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') ); 
    7171    $this->smarty->register_modifier( 'get_extent', array(&$this, 'get_extent') ); 
    7272    $this->smarty->register_block('html_head', array(&$this, 'block_html_head') ); 
    73     $this->smarty->register_function('known_script', array(&$this, 'func_known_script') ); 
     73    $this->smarty->register_function( 'known_script', array(&$this, 'func_known_script') ); 
    7474    $this->smarty->register_prefilter( array('Template', 'prefilter_white_space') ); 
    7575    if ( $conf['compiled_template_cache_language'] ) 
     
    9999    include($root.'/'.$theme.'/themeconf.inc.php'); 
    100100 
    101     if (isset($themeconf['parent'])) 
     101    if (isset($themeconf['parent']) and $themeconf['parent'] != $theme) 
    102102    { 
    103103      $this->set_theme($root, $themeconf['parent'], $path); 
     
    386386   * language 
    387387   */ 
    388   static function mod_translate($text) 
    389   { 
    390     return l10n($text); 
     388  public function mod_translate($text, $domain='piwigo') 
     389  { 
     390    return l10n($text, $domain); 
    391391  } 
    392392 
     
    561561class PwgTemplateAdapter 
    562562{ 
    563   function l10n($text) 
    564   { 
    565     return l10n($text); 
    566   } 
    567  
    568   function l10n_dec($s, $p, $v) 
    569   { 
    570     return l10n_dec($s, $p, $v); 
     563  function l10n($text, $domain='piwigo') 
     564  { 
     565    return l10n($text, $domain); 
     566  } 
     567 
     568  function l10n_dec($s, $p, $v, $domain='piwigo') 
     569  { 
     570    return l10n_dec($s, $p, $v, $domain); 
    571571  } 
    572572 
  • branches/gettext/themes/default/template/about.tpl

    r5095 r5167  
    44      <li> 
    55        <a href="{$U_HOME}" title="{'return to homepage'|@translate}"> 
    6           <img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"> 
     6          <img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"> 
    77        </a> 
    88      </li> 
  • branches/gettext/themes/default/template/comments.tpl

    r5095 r5167  
    33  <div class="titrePage"> 
    44    <ul class="categoryActions"> 
    5       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     5      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    66    </ul> 
    77    <h2>{'User comments'|@translate}</h2> 
  • branches/gettext/themes/default/template/identification.tpl

    r5095 r5167  
    77      <li><a href="{$U_REGISTER}" title="{'Register'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/register.png" class="button" alt="{'Register'|@translate}"></a></li> 
    88      {/if} 
    9       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     9      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    1010    </ul> 
    1111    <h2>{'Identification'|@translate}</h2> 
  • branches/gettext/themes/default/template/nbm.tpl

    r5095 r5167  
    33  <div class="titrePage"> 
    44    <ul class="categoryActions"> 
    5       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     5      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    66    </ul> 
    77    <h2>{'Notification'|@translate}</h2> 
  • branches/gettext/themes/default/template/notification.tpl

    r5095 r5167  
    77  <div class="titrePage"> 
    88    <ul class="categoryActions"> 
    9       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     9      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    1010    </ul> 
    1111    <h2>{'Notification'|@translate}</h2> 
  • branches/gettext/themes/default/template/password.tpl

    r5095 r5167  
    33  <div class="titrePage"> 
    44    <ul class="categoryActions"> 
    5       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     5      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    66    </ul> 
    77    <h2>{'Password forgotten'|@translate}</h2> 
  • branches/gettext/themes/default/template/profile.tpl

    r5095 r5167  
    1313  <div class="titrePage"> 
    1414    <ul class="categoryActions"> 
    15       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     15      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    1616    </ul> 
    1717    <h2>{'Profile'|@translate}</h2> 
  • branches/gettext/themes/default/template/register.tpl

    r5095 r5167  
    55  <div class="titrePage"> 
    66    <ul class="categoryActions"> 
    7       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     7      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$ROOT_URL}{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    88    </ul> 
    99    <h2>{'Registration'|@translate}</h2> 
  • branches/gettext/themes/default/template/search.tpl

    r5095 r5167  
    2323    <ul class="categoryActions"> 
    2424      <li><a href="{$U_HELP}" onclick="popuphelp(this.href); return false;" title="{'Help'|@translate}" rel="nofollow"><img src="{$ROOT_URL}{$themeconf.icon_dir}/help.png" class="button" alt="(?)"></a></li> 
    25       <li><a href="{$U_HOME}" title="{'Home'|@translate}" rel="Home"><img src="{$ROOT_URL}{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     25      <li><a href="{$U_HOME}" title="{'Home'|@translate}" rel="Home"><img src="{$ROOT_URL}{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    2626    </ul> 
    2727    <h2>{'Search'|@translate}</h2> 
  • branches/gettext/themes/default/template/tags.tpl

    r5095 r5167  
    1111                {/if} 
    1212 
    13                         <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     13                        <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    1414                </ul> 
    1515                <h2>{'Tags'|@translate}</h2> 
  • branches/gettext/themes/default/template/upload.tpl

    r5095 r5167  
    99  <div class="titrePage"> 
    1010    <ul class="categoryActions"> 
    11       <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/Home.png" class="button" alt="{'Home'|@translate}"></a></li> 
     11      <li><a href="{$U_HOME}" title="{'Home'|@translate}"><img src="{$themeconf.icon_dir}/home.png" class="button" alt="{'Home'|@translate}"></a></li> 
    1212    </ul> 
    1313    <h2>{'Upload a picture'|@translate}</h2> 
Note: See TracChangeset for help on using the changeset viewer.