Changeset 5021 for trunk/include


Ignore:
Timestamp:
Mar 2, 2010, 3:54:22 PM (14 years ago)
Author:
nikrou
Message:

Feature 1451 : localization with gettext
Use php-gettext (developpement version rev43, because of php5.3) as fallback
Use native language (english) instead of key for translation
Keep directory en_UK for english customization
Need some refactoring for plurals

Todo : managing plugins in the same way

Location:
trunk/include
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/calendar_base.class.php

    r5014 r5021  
    9696    elseif ('any' === $date_component )
    9797    {
    98       $label = l10n('calendar_any');
     98      $label = l10n('All');
    9999    }
    100100    return $label;
     
    193193          );
    194194      $nav_bar_datas[]=array(
    195         'LABEL' => l10n('calendar_any'),
     195        'LABEL' => l10n('All'),
    196196        'URL' => $url
    197197      );
  • trunk/include/common.inc.php

    r5014 r5021  
    174174    $user['internal_status']['guest_must_be_guest'] === true)
    175175{
    176   $header_msgs[] = l10n('guest_must_be_guest');
     176  $header_msgs[] = l10n('Bad status for user "guest", using default status. Please notify the webmaster.');
    177177}
    178178
    179179if ($conf['gallery_locked'])
    180180{
    181   $header_msgs[] = l10n('gallery_locked_message');
     181  $header_msgs[] = l10n('The gallery is locked for maintenance. Please, come back later.');
    182182
    183183  if ( script_basename() != 'identification' and !is_admin() )
     
    186186    @header('Retry-After: 900');
    187187    header('Content-Type: text/html; charset='.get_pwg_charset());
    188     echo '<a href="'.get_absolute_root_url(false).'identification.php">'.l10n('gallery_locked_message').'</a>';
     188    echo '<a href="'.get_absolute_root_url(false).'identification.php">'.l10n('The gallery is locked for maintenance. Please, come back later.').'</a>';
    189189    echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size
    190190    exit();
     
    204204if (is_adviser())
    205205{
    206   $header_msgs[] = l10n('adviser_mode_enabled');
     206  $header_msgs[] = l10n('Adviser mode enabled');
    207207}
    208208
  • trunk/include/functions.inc.php

    r5014 r5021  
    3131include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
    3232include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
     33include_once( PHPWG_ROOT_PATH .'include/php-gettext/gettext.inc.php' );
    3334
    3435//----------------------------------------------------------- generic functions
     
    4041                         );
    4142  if (!empty($fields))
    42   {
     43  { 
    4344    $fields = ','.$fields;
    4445  }
     
    174175    if ($mkd==false)
    175176    {
    176       !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
     177      !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no write access'));
    177178      return false;
    178179    }
     
    190191  if ( !is_writable($dir) )
    191192  {
    192     !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
     193    !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no write access'));
    193194    return false;
    194195  }
     
    214215  {
    215216    array_push($errors,
    216           '['.$dirname.'] : '.l10n('no_write_access'));
     217          '['.$dirname.'] : '.l10n('no write access'));
    217218    return false;
    218219  }
     
    621622  if (empty($msg))
    622623  {
    623     $msg = nl2br(l10n('redirect_msg'));
     624    $msg = nl2br(l10n('Redirection...'));
    624625  }
    625626
     
    867868 * @return string
    868869 */
    869 function l10n($key)
    870 {
    871   global $lang, $conf;
    872 
    873   if ($conf['debug_l10n'] and !isset($lang[$key]) and !empty($key))
    874   {
    875     trigger_error('[l10n] language key "'.$key.'" is not defined', E_USER_WARNING);
    876   }
    877 
    878   return isset($lang[$key]) ? $lang[$key] : $key;
     870function 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
     889  T_textdomain($textdomain);
     890 
     891  return T_gettext($key);
    879892}
    880893
     
    888901 * @return string
    889902 */
    890 function l10n_dec($singular_fmt_key, $plural_fmt_key, $decimal)
    891 {
    892   global $lang_info;
    893 
    894   return
    895     sprintf(
    896       l10n((
    897         (($decimal > 1) or ($decimal == 0 and $lang_info['zero_plural']))
    898           ? $plural_fmt_key
    899           : $singular_fmt_key
    900         )), $decimal);
    901 }
     903function 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
     923  T_textdomain($textdomain);
     924
     925  return sprintf(T_ngettext($singular_fmt_key,
     926                            $plural_fmt_key,
     927                            $decimal),
     928                 $decimal
     929                 );
     930}
     931
    902932/*
    903933 * returns a single element to use with l10n_args
     
    14361466  {
    14371467    $cache['get_icon']['title'] = sprintf(
    1438       l10n('elements posted during the last %d days'),
     1468      l10n('images posted during the last %d days'),
    14391469      $user['recent_period']
    14401470      );
  • trunk/include/functions_category.inc.php

    r5014 r5021  
    287287  return trigger_event('get_category_preferred_image_orders',
    288288    array(
    289     array(l10n('default_sort'), '', true),
     289    array(l10n('Default'), '', true),
    290290    array(l10n('Average rate'), 'average_rate DESC', $conf['rate']),
    291     array(l10n('most_visited_cat'), 'hit DESC', true),
     291    array(l10n('Most visited'), 'hit DESC', true),
    292292    array(l10n('Creation date'), 'date_creation DESC', true),
    293293    array(l10n('Post date'), 'date_available DESC', true),
     
    298298      ('categories' == @$page['section'] and !isset($page['flat']) and !isset($page['chronology_field']) )
    299299      ),
    300     array( l10n('permissions'), 'level DESC', is_admin() )
     300    array( l10n('Permissions'), 'level DESC', is_admin() )
    301301    ));
    302302}
     
    480480      if (! $short_message)
    481481      {
    482         $display_text.= ' '.l10n('images_available_cpl');
     482        $display_text.= ' '.l10n('in this category');
    483483      }
    484484    }
  • trunk/include/functions_comment.inc.php

    r5014 r5021  
    104104      if ( $row['user_exists'] == 1 )
    105105      {
    106         array_push($infos, l10n('comment_user_exists') );
     106        array_push($infos, l10n('This login is already used by another user') );
    107107        $comment_action='reject';
    108108      }
     
    141141    if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 )
    142142    {
    143       array_push( $infos, l10n('comment_anti-flood') );
     143      array_push( $infos, l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
    144144      $comment_action='reject';
    145145    }
     
    269269    if ( pwg_db_num_rows( pwg_query( $query ) ) > 0 )
    270270    {
    271       //?? array_push( $infos, l10n('comment_anti-flood') );
     271      //?? array_push( $infos, l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
    272272      $comment_action='reject';
    273273    }
  • trunk/include/functions_html.inc.php

    r5014 r5021  
    293293  {
    294294    echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
    295     echo '<div style="text-align:center;">'.l10n('access_forbiden').'<br>';
    296     echo '<a href="'.get_root_url().'identification.php">'.l10n('identification').'</a>&nbsp;';
    297     echo '<a href="'.make_index_url().'">'.l10n('home').'</a></div>';
     295    echo '<div style="text-align:center;">'.l10n('You are not authorized to access the requested page').'<br>';
     296    echo '<a href="'.get_root_url().'Identification.php">'.l10n('Identification').'</a>&nbsp;';
     297    echo '<a href="'.make_index_url().'">'.l10n('Home').'</a></div>';
    298298    echo str_repeat( ' ', 512); //IE6 doesn't error output if below a size
    299299    exit();
     
    400400{
    401401  global $page;
    402   $title = count($page['tags']) > 1 ? l10n('Tags') : l10n('Tag');
     402  $title = count($page['tags']) > 1 ? l10n('Tag') : l10n('Tag');
    403403  $title.= ' ';
    404404
     
    415415        )
    416416      .'" title="'
    417       .l10n('See elements linked to this tag only')
     417      .l10n('See images linked to this tag only')
    418418      .'">'
    419419      .$page['tags'][$i]['name']
     
    432432          )
    433433        .'" style="border:none;" title="'
    434         .l10n('remove this tag')
     434        .l10n('remove this tag from the list')
    435435        .'"><img src="'
    436436        .get_root_url().get_themeconf('icon_dir').'/remove_s.png'
  • trunk/include/functions_mail.inc.php

    r5014 r5021  
    647647          'PHPWG_URL' => PHPWG_URL,
    648648
    649           'TITLE_MAIL' => urlencode(l10n('title_send_mail')),
     649          'TITLE_MAIL' => urlencode(l10n('A comment on your site')),
    650650          'MAIL' => get_webmaster_mail_address()
    651651          ));
  • trunk/include/functions_notification.inc.php

    r5014 r5021  
    530530        .' ('
    531531        .'<a href="'.make_index_url(array('section'=>'recent_pics')).'">'
    532           .l10n('recent_pics_cat').'</a>'
     532          .l10n('Recent pictures').'</a>'
    533533        .')'
    534534        .'</li><br>';
  • trunk/include/functions_user.inc.php

    r5014 r5021  
    4848  if ( !preg_match( $regex, $mail_address ) )
    4949  {
    50     return l10n('reg_err_mail_address');
     50    return l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
    5151  }
    5252
     
    6262    if ($count != 0)
    6363    {
    64       return l10n('reg_err_mail_address_dbl');
     64      return l10n('a user use already this mail address');
    6565    }
    6666  }
     
    8787    if ($count > 0)
    8888    {
    89       return l10n('reg_err_login5');
     89      return l10n('this login is already used');
    9090    }
    9191  }
     
    9999  if ($login == '')
    100100  {
    101     array_push($errors, l10n('reg_err_login1'));
     101    array_push($errors, l10n('Please, enter a login'));
    102102  }
    103103  if (preg_match('/^.* $/', $login))
    104104  {
    105     array_push($errors, l10n('reg_err_login2'));
     105    array_push($errors, l10n('login mustn\'t end with a space character'));
    106106  }
    107107  if (preg_match('/^ .*$/', $login))
    108108  {
    109     array_push($errors, l10n('reg_err_login3'));
     109    array_push($errors, l10n('login mustn\'t start with a space character'));
    110110  }
    111111  if (get_userid($login))
    112112  {
    113     array_push($errors, l10n('reg_err_login5'));
     113    array_push($errors, l10n('this login is already used'));
    114114  }
    115115  $mail_error = validate_mail_address(null, $mail_address);
  • trunk/include/menubar.inc.php

    r5014 r5021  
    149149        array(
    150150          'URL' => make_index_url(array('section' => 'favorites')),
    151           'TITLE' => l10n('favorite_cat_hint'),
    152           'NAME' => l10n('favorite_cat')
     151          'TITLE' => l10n('display my favorites pictures'),
     152          'NAME' => l10n('My favorites')
    153153          );
    154154    }
     
    157157      array(
    158158        'URL' => make_index_url(array('section' => 'most_visited')),
    159         'TITLE' => l10n('most_visited_cat_hint'),
    160         'NAME' => l10n('most_visited_cat')
     159        'TITLE' => l10n('display most visited pictures'),
     160        'NAME' => l10n('Most visited')
    161161      );
    162162
     
    166166        array(
    167167          'URL' => make_index_url(array('section' => 'best_rated')),
    168           'TITLE' => l10n('best_rated_cat_hint'),
    169           'NAME' => l10n('best_rated_cat')
     168          'TITLE' => l10n('display best rated items'),
     169          'NAME' => l10n('Best rated')
    170170        );
    171171    }
     
    174174      array(
    175175        'URL' => get_root_url().'random.php',
    176         'TITLE' => l10n('random_cat_hint'),
    177         'NAME' => l10n('random_cat'),
     176        'TITLE' => l10n('display a set of random pictures'),
     177        'NAME' => l10n('Random pictures'),
    178178        'REL'=> 'rel="nofollow"'
    179179      );
     
    182182      array(
    183183        'URL' => make_index_url(array('section' => 'recent_pics')),
    184         'TITLE' => l10n('recent_pics_cat_hint'),
    185         'NAME' => l10n('recent_pics_cat'),
     184        'TITLE' => l10n('display most recent pictures'),
     185        'NAME' => l10n('Recent pictures'),
    186186      );
    187187
     
    189189      array(
    190190        'URL' => make_index_url(array('section' => 'recent_cats')),
    191         'TITLE' => l10n('recent_cats_cat_hint'),
    192         'NAME' => l10n('recent_cats_cat'),
     191        'TITLE' => l10n('display recently updated categories'),
     192        'NAME' => l10n('Recent categories'),
    193193      );
    194194
     
    205205            )
    206206          ),
    207         'TITLE' => l10n('calendar_hint'),
    208         'NAME' => l10n('calendar'),
     207        'TITLE' => l10n('display each day with pictures, month per month'),
     208        'NAME' => l10n('Calendar'),
    209209        'REL'=> 'rel="nofollow"'
    210210      );
     
    231231    $block->data['search'] =
    232232      array(
    233         'TITLE'=>l10n('hint_search'),
     233        'TITLE'=>l10n('search'),
    234234        'NAME'=>l10n('Search'),
    235235        'URL'=> get_root_url().'search.php',
     
    240240    $block->data['comments'] =
    241241      array(
    242         'TITLE'=>l10n('hint_comments'),
    243         'NAME'=>l10n('comments'),
     242        'TITLE'=>l10n('See last users comments'),
     243        'NAME'=>l10n('Comments'),
    244244        'URL'=> get_root_url().'comments.php',
    245245      );
     
    248248    $block->data['about'] =
    249249      array(
    250         'TITLE'     => l10n('about_page_title'),
     250        'TITLE'     => l10n('About Piwigo'),
    251251        'NAME'      => l10n('About'),
    252252        'URL' => get_root_url().'about.php',
  • trunk/include/picture_comment.inc.php

    r5014 r5021  
    5959  {
    6060    case 'moderate':
    61       array_push( $infos, l10n('comment_to_validate') );
     61      array_push( $infos, l10n('An administrator must authorize your comment before it is visible.') );
    6262    case 'validate':
    63       array_push( $infos, l10n('comment_added'));
     63      array_push( $infos, l10n('Your comment has been registered'));
    6464      break;
    6565    case 'reject':
    6666      set_status_header(403);
    67       array_push($infos, l10n('comment_not_added') );
     67      array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') );
    6868      break;
    6969    default:
  • trunk/include/section_init.inc.php

    r5014 r5021  
    238238  else
    239239  {
    240     $page['title'] = l10n('no_category');
     240    $page['title'] = l10n('Home');
    241241  }
    242242
     
    362362        'items' => $search_result['items'],
    363363        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    364                   .l10n('search_result').'</a>',
     364                  .l10n('Search results').'</a>',
    365365        )
    366366      );
     
    376376      $page,
    377377      array(
    378         'title' => l10n('favorites')
     378        'title' => l10n('Favorites')
    379379            )
    380380    );
     
    457457      array(
    458458        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    459                   .l10n('recent_pics_cat').'</a>',
     459                  .l10n('Recent pictures').'</a>',
    460460        'items' => array_from_query($query, 'id'),
    461461        )
     
    470470      $page,
    471471      array(
    472         'title' => l10n('recent_cats_cat'),
     472        'title' => l10n('Recent categories'),
    473473        )
    474474      );
     
    495495      array(
    496496        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    497                   .$conf['top_number'].' '.l10n('most_visited_cat').'</a>',
     497                  .$conf['top_number'].' '.l10n('Most visited').'</a>',
    498498        'items' => array_from_query($query, 'id'),
    499499        )
     
    521521      array(
    522522        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    523                   .$conf['top_number'].' '.l10n('best_rated_cat').'</a>',
     523                  .$conf['top_number'].' '.l10n('Best rated').'</a>',
    524524        'items' => array_from_query($query, 'id'),
    525525        )
     
    544544      array(
    545545        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    546                     .l10n('random_cat').'</a>',
     546                    .l10n('Random pictures').'</a>',
    547547        'items' => array_from_query($query, 'id'),
    548548        )
  • trunk/include/ws_functions.inc.php

    r5014 r5021  
    563563  {
    564564    case 'reject':
    565       array_push($infos, l10n('comment_not_added') );
     565      array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') );
    566566      return new PwgError(403, implode("\n", $infos) );
    567567    case 'validate':
Note: See TracChangeset for help on using the changeset viewer.