b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: admin ] [ index: admin ] [ all elements ]

Source for file _set_regional.form.php

Documentation is available at _set_regional.form.php

  1. <?php
  2. /**
  3.  * This file implements the general settings form
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package admin
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. param'locale''string''' );
  14.  
  15. if!empty($locale&& $action != 'extract' )
  16. {
  17.     param'template''string''' );
  18.     ?>
  19.     <form class="fform" method="post" action="b2options.php?tab=regional" name="createnew">
  20.         <input type="hidden" name="notransext" value="<?php echo $notransext;?>" />
  21.         <input type="hidden" name="action" value="<?php echo ( ($locale == '_new_''createlocale' 'updatelocale' ?>" />
  22.         <fieldset id="createnew">
  23.         <legend><?php echo ( ($locale == '_new_'T_('Create new locale'T_('Edit locale') ) ?></legend>
  24.  
  25.         <?php
  26.         // read template
  27.  
  28.         ifisset($locales[$template]) )
  29.         {
  30.             $ltemplate $locales$template ];
  31.             $newlocale $template;
  32.         }
  33.         elseif$locale != '_new_' && isset($locales$locale ]) )
  34.         {
  35.             $ltemplate $locales$locale ];
  36.             $newlocale $locale;
  37.         }
  38.         else
  39.         {
  40.             $newlocale '';
  41.         }
  42.  
  43.         if$locale != '_new_' )
  44.         // we need to remember this for updating locale
  45.             echo '<input type="hidden" name="oldloc_locale" value="'.$newlocale.'" />';
  46.         }
  47.         form_text'newloc_locale'$newlocale20T_('Locale')sprintf(T_('The first two letters should be a <a %s>ISO 639 language code</a>. The last two letters should be a <a %s>ISO 3166 country code</a>.')'href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_15.html#SEC221"''href="http://www.gnu.org/software/gettext/manual/html_chapter/gettext_16.html#SEC222"')20 );
  48.         form_checkbox'newloc_enabled'(isset($ltemplate['enabled']&& $ltemplate['enabled'])T_('Enabled'),    T_('Should this locale be available to users?') );
  49.         form_text'newloc_name'(isset($ltemplate['name']$ltemplate['name''')40T_('Name'),
  50.             T_('name of the locale')40 );
  51.         form_text'newloc_charset'(isset($ltemplate['charset']$ltemplate['charset''')20T_('Charset')T_('Must match the lang file charset.')15 );
  52.         form_text'newloc_datefmt'(isset($ltemplate['datefmt']$ltemplate['datefmt''')20T_('Date format')T_('See below.')10 );
  53.         form_text'newloc_timefmt'(isset($ltemplate['timefmt']$ltemplate['timefmt''')20T_('Time format')T_('See below.')10 );
  54.         form_text'newloc_messages'(isset($ltemplate['messages']$ltemplate['messages''')20T_('Lang file'),
  55.             T_('the lang file to use, from the <code>locales</code> subdirectory')20 );
  56.         form_text'newloc_priority'(isset($ltemplate['priority']$ltemplate['priority''')3T_('Priority'),
  57.             T_('1 is highest. Priority is important when selecting a locale from a language code and several locales match the same language; this can happen when detecting browser language. Priority also affects the order in which locales are displayed in dropdown boxes, etc.'));
  58.  
  59.         // generate Javascript array of locales to warn in case of overwriting
  60.         $l_warnfor "'".implode("', '"array_keys($locales))."'";
  61.         if$locale != '_new_' )
  62.         // remove the locale we want to edit from the generated array
  63.             $l_warnfor str_replace("'$newlocale'""'thiswillneverevermatch'"$l_warnfor);
  64.         }
  65.         echo '
  66.         <div class="input">
  67.         <input type="submit" name="submit" value="'.( ($locale == '_new_'T_('Create'T_('Update') ).'" class="search" onclick="var Locales = new Array('.$l_warnfor.'); while( Locales.length > 0 ){ check = Locales.shift(); if( document.createnew.newloc_locale.value == check ){ c = \''/* TRANS: Warning this is a javascript string */ T_("This will replace locale \'%s\'. Ok?").'\'.replace(/%s/, check); return confirm( c )}};" />
  68.         <input type="reset" value="'.format_to_output(T_('Reset')'formvalue').'" class="search" />
  69.         </div>';
  70.         ?>
  71.         <div class="panelinfo">
  72.             <h3><?php echo T_('Flags'?></h3>
  73.             <p><?php printf(T_('The flags are stored in subdirectories from <code>%s</code>. Their filename is equal to the country part of the locale (characters 4-5); file extension is .gif .')'/'.$img_subdir.'/flags/')?></p>
  74.             <h3><?php echo T_('Date/Time Formats'?></h3>
  75.             <p><?php echo T_('The following characters are recognized in the format strings:'?></p>
  76.             <p>
  77.             <?php echo T_('a - "am" or "pm"'?><br />
  78.             <?php echo T_('A - "AM" or "PM"'?><br />
  79.             <?php echo T_('B - Swatch Internet time'?><br />
  80.             <?php echo T_('c - ISO 8601 date (Requires PHP 5); i.e. "2004-02-12T15:19:21+00:00"'?><br />
  81.             <?php echo T_('d - day of the month, 2 digits with leading zeros; i.e. "01" to "31"'?><br />
  82.             <?php echo T_('D - day of the week, textual, 3 letters; i.e. "Fri"'?><br />
  83.             <?php echo T_('e - day of the week, 1 letter; i.e. "F"'?><br />
  84.             <?php echo T_('F - month, textual, long; i.e. "January"'?><br />
  85.             <?php echo T_('g - hour, 12-hour format without leading zeros; i.e. "1" to "12"'?><br />
  86.             <?php echo T_('G - hour, 24-hour format without leading zeros; i.e. "0" to "23"'?><br />
  87.             <?php echo T_('h - hour, 12-hour format; i.e. "01" to "12"'?><br />
  88.             <?php echo T_('H - hour, 24-hour format; i.e. "00" to "23"'?><br />
  89.             <?php echo T_('i - minutes; i.e. "00" to "59"'?><br />
  90.             <?php echo T_('I (capital i) - "1" if Daylight Savings Time, "0" otherwise.'?><br />
  91.             <?php echo T_('j - day of the month without leading zeros; i.e. "1" to "31"'?><br />
  92.             <?php echo T_('l (lowercase "L") - day of the week, textual, long; i.e. "Friday"'?><br />
  93.             <?php echo T_('L - boolean for whether it is a leap year; i.e. "0" or "1"'?><br />
  94.             <?php echo T_('m - month; i.e. "01" to "12"'?><br />
  95.             <?php echo T_('M - month, textual, 3 letters; i.e. "Jan"'?><br />
  96.             <?php echo T_('n - month without leading zeros; i.e. "1" to "12"'?><br />
  97.             <?php echo T_('O - Difference to Greenwich time (GMT) in hours; i.e. "+0200"'?><br />
  98.             <?php echo T_('r - RFC 822 formatted date; i.e. "Thu, 21 Dec 2000 16:01:07 +0200"'?><br />
  99.             <?php echo T_('s - seconds; i.e. "00" to "59"'?><br />
  100.             <?php echo T_('S - English ordinal suffix, textual, 2 characters; i.e. "th", "nd"'?><br />
  101.             <?php echo T_('t - number of days in the given month; i.e. "28" to "31"'?><br />
  102.             <?php echo T_('T - Timezone setting of this machine; i.e. "MDT"'?><br />
  103.             <?php echo T_('U - seconds since the epoch'?><br />
  104.             <?php echo T_('w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)'?><br />
  105.             <?php echo T_('W - ISO-8601 week number of year, weeks starting on Monday; i.e. "42"'?><br />
  106.             <?php echo T_('Y - year, 4 digits; i.e. "1999"'?><br />
  107.             <?php echo T_('y - year, 2 digits; i.e. "99"'?><br />
  108.             <?php echo T_('z - day of the year; i.e. "0" to "365"'?><br />
  109.             <?php echo T_('Z - timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.'?>
  110.             </p>
  111.             <?php echo T_('isoZ - full ISO 8601 format, equivalent to Y-m-d\TH:i:s\Z'?><br />
  112.             <p><?php echo T_('Unrecognized characters in the format string will be printed as-is.<br />
  113.             You can escape characters by preceding them with a \ to print them as-is.'?></p>
  114.         </div>
  115.         </fieldset>
  116.     </form>
  117.     <?php
  118. }
  119. else
  120. // show main form
  121.     if!$locales[$Settings->get('default_locale')]['enabled')
  122.     // default locale is not enabled
  123.         echo '<div class="error">' T_('Note: default locale is not enabled.''</div>';
  124.     }
  125.     ?>
  126.     <form class="fform" name="form" action="b2options.php?tab=regional" method="post">
  127.         <input type="hidden" name="action" value="update" />
  128.         <input type="hidden" name="notransext" value="<?php echo $notransext;?>" />
  129.  
  130.         <fieldset>
  131.             <legend><?php echo T_('Regional settings'?></legend>
  132.  
  133.             <?php
  134.             form_text'newtime_difference'$Settings->get('time_difference')3T_('Time difference')sprintf'['T_('in hours')'] 'T_('If you\'re not on the timezone of your server. Current server time is: %s.')date_i18nlocale_timefmt()$servertimenow ) ));
  135.             form_select'newdefault_locale'$Settings->get('default_locale')'locale_options'T_('Default locale')T_('Overriden by browser config, user locale or blog locale (in this order).'));
  136.             ?>
  137.  
  138.         </fieldset>
  139.  
  140.         <fieldset>
  141.         <legend><?php echo T_('Available locales')?></legend>
  142.  
  143.         <p class="center"><?php
  144.         if!$notransext )
  145.         {
  146.             echo '<a href="b2options.php?tab=regional&amp;notransext=1">' T_('Hide translation info')'</a>';
  147.             $showtranslationpercentage 1;
  148.         }
  149.         else
  150.         {
  151.             echo '<a href="b2options.php?tab=regional">' T_('Show translation info')'</a>';
  152.             $showtranslationpercentage 0;
  153.         }
  154.         ?></p>
  155.  
  156.         <table class="grouped" cellspacing="0">
  157.         <tr>
  158.             <th><?php echo T_('Locale'?></th>
  159.             <th><?php echo T_('Enabled'?></th>
  160.             <th><?php echo T_('Name'?></th>
  161.             <th><?php echo T_('Date fmt'?></th>
  162.             <th><?php echo T_('Time fmt'?></th>
  163.             <?php if$current_User->check_perm'options''edit' ) )
  164.             ?>
  165.                 <th><?php echo T_('Edit'?></th>
  166.                 <?php
  167.             }
  168.             if$showtranslationpercentage )
  169.             {
  170.                 ?>
  171.                 <th><?php echo T_('Strings'?></th>
  172.                 <th><?php echo T_('Translated'?></th>
  173.                 <?php
  174.                 if$current_User->check_perm'options''edit' && $allow_po_extraction )
  175.                 ?>
  176.                     <th><?php echo T_('Extract'?></th>
  177.                     <?php
  178.                 }
  179.             ?>
  180.         </tr>
  181.         <?php
  182.         $i 0// counter to distinguish POSTed locales later
  183.         foreach$locales as $lkey => $lval )
  184.         {
  185.             $i++;
  186.             ?>
  187.             <tr <?php if($i%== 1echo 'class="odd"' ?>>
  188.             <td class="left" title="<?php echo T_('Priority').': '.$locales[$lkey]['priority'].', '.T_('Charset').': '.$locales[$lkey]['charset'].', '.T_('Lang file').': '.$locales[$lkey]['messages'?>">
  189.                 <?php
  190.                 echo '<input type="hidden" name="loc_'.$i.'_locale" value="'.$lkey.'" />';
  191.                 locale_flag$lkey );
  192.                 echo'
  193.                 <strong>';
  194.                 if$current_User->check_perm'options''edit' ) )
  195.                 {
  196.                     echo '<a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;locale='.$lkey.'" title="'.T_('Edit locale').'">';
  197.                 }
  198.                 echo $lkey;
  199.                 if$current_User->check_perm'options''edit' ) )
  200.                 {
  201.                     echo '</a>';
  202.                 }
  203.                 echo '</strong>
  204.             </td>
  205.             <td class="center">
  206.                 <input type="checkbox" name="loc_'.$i.'_enabled" value="1"'$locales[$lkey]['enabled''checked="checked"' '' ).' />
  207.             </td>
  208.             <td>
  209.                 <input type="text" name="loc_'.$i.'_name" value="'.format_to_output$locales[$lkey]['name']'formvalue' ).'" maxlength="40" size="17" />
  210.             </td>
  211.             <td>
  212.                 <input type="text" name="loc_'.$i.'_datefmt" value="'.format_to_output$locales[$lkey]['datefmt']'formvalue' ).'" maxlength="10" size="6" />
  213.             </td>
  214.             <td>
  215.                 <input type="text" name="loc_'.$i.'_timefmt" value="'.format_to_output$locales[$lkey]['timefmt']'formvalue' ).'" maxlength="10" size="6" />
  216.             </td>';
  217.  
  218.             if$current_User->check_perm'options''edit' ) )
  219.             {
  220.                 echo '<td class="left">';
  221.                 if$i )
  222.                 // show "move prio up"
  223.                     echo '<a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;prioup='.$lkey.'"><img src="img/arrowup.png" alt="'.T_('up').'" title="'.T_('Move priority up').'" width="14" height="14" class="middle" /></a>';
  224.                 }
  225.                 else
  226.                 {
  227.                     echo '<img src="img/blank.gif" width="14" alt="" />';
  228.                 }
  229.  
  230.                 if$i count($locales) )
  231.                 // show "move prio down"
  232.                     echo '<a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;priodown='.$lkey.'"><img src="img/arrowdown.png" alt="'.T_('down').'" title="'.T_('Move priority down').'" width="14" height="14" class="middle" /></a>';
  233.                 }
  234.                 else
  235.                 {
  236.                     echo '<img src="img/blank.gif" width="14" alt="" />';
  237.                 }
  238.                 echo '
  239.                 <a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;locale=_new_&amp;template='.$lkey.'" title="'.T_('Copy locale').'"><img src="img/copy.gif" width="13" height="13" class="middle" alt="'.T_('Copy').'" title="'.T_('Copy locale').'" /></a>
  240.  
  241.                 <a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;locale='.$lkey.'" title="'.T_('Edit locale').'"><img src="img/properties.png" width="18" height="13" alt="'.T_('Edit').'" title="'.T_('Edit locale').'" class="middle" /></a>
  242.                 ';
  243.                 ifisset($lval'fromdb' ]) )
  244.                 // allow to delete locales loaded from db
  245.                     $l_atleastonefromdb 1;
  246.                     echo '<a href="b2options.php?tab=regional'.($notransext '&amp;notransext=1' '').'&amp;delete='.$lkey.'"><img src="img/xross.gif" height="13" width="13" class="middle" alt="'.T_('Reset').'" title="'.T_('Reset custom settings').'" /></a>';
  247.                 }
  248.                 echo '</td>';
  249.             }
  250.  
  251.             if$showtranslationpercentage )
  252.             {
  253.                 // Get PO file for that locale:
  254.                 $po_file dirname(__FILE__).'/'.$core_dirout.'/'.$locales_subdir.'/'.$locales[$lkey]['messages'].'/LC_MESSAGES/messages.po';
  255.                 ifis_file$po_file ) )
  256.                 {
  257.                     echo '<td class="center" colspan="'.(+ (int)$allow_po_extraction).'">'.T_('No language file...').'</td>';
  258.                 }
  259.                 else
  260.                 {    // File exists:
  261.                     $lines file$po_file );
  262.                     $lines['';    // Adds a blank line at the end in order to ensure complete handling of the file
  263.                     $all 0;
  264.                     $fuzzy 0;
  265.                     $this_fuzzy false;
  266.                     $untranslated=0;
  267.                     $translated=0;
  268.                     $status='-';
  269.                     $matches array();
  270.                     foreach ($lines as $line)
  271.                     {
  272.                         // echo 'LINE:', $line, '<br />';
  273.                         if(trim($line== '' )
  274.                         {    // Blank line, go back to base status:
  275.                             if$status == 't' )
  276.                             {    // ** End of a translation ** :
  277.                                 if$msgstr == '' )
  278.                                 {
  279.                                     $untranslated++;
  280.                                     // echo 'untranslated: ', $msgid, '<br />';
  281.                                 }
  282.                                 else
  283.                                 {
  284.                                     $translated++;
  285.                                 }
  286.                                 if$msgid == '' && $this_fuzzy )
  287.                                 {    // It's OK if first line is fuzzy
  288.                                     $fuzzy--;
  289.                                 }
  290.                                 $msgid '';
  291.                                 $msgstr '';
  292.                                 $this_fuzzy false;
  293.                             }
  294.                             $status '-';
  295.                         }
  296.                         elseif( ($status=='-'&& preg_match'#^msgid "(.*)"#'$line$matches))
  297.                         {    // Encountered an original text
  298.                             $status 'o';
  299.                             $msgid $matches[1];
  300.                             // echo 'original: "', $msgid, '"<br />';
  301.                             $all++;
  302.                         }
  303.                         elseif( ($status=='o'&& preg_match'#^msgstr "(.*)"#'$line$matches))
  304.                         {    // Encountered a translated text
  305.                             $status 't';
  306.                             $msgstr $matches[1];
  307.                             // echo 'translated: "', $msgstr, '"<br />';
  308.                         }
  309.                         elseifpreg_match'#^"(.*)"#'$line$matches))
  310.                         {    // Encountered a followup line
  311.                             if ($status=='o')
  312.                                 $msgid .= $matches[1];
  313.                             elseif ($status=='t')
  314.                                 $msgstr .= $matches[1];
  315.                         }
  316.                         elseif(strpos($line,'#, fuzzy'=== 0)
  317.                         {
  318.                             $this_fuzzy true;
  319.                             $fuzzy++;
  320.                         }
  321.                     }
  322.                     // $all=$translated+$fuzzy+$untranslated;
  323.                     echo "\n\t<td class=\"center\">"$all ."</td>";
  324.                     $percent_done $all round(($translated-$fuzzy/2)/$all*1000;
  325.                     $color sprintf'%02x%02x00'255 round($percent_done 2.55)round($percent_done 2.55) );
  326.                     echo "\n\t<td class=\"center\" style=\"background-color:#"$color "\">"$percent_done ." %</td>";
  327.                 }
  328.  
  329.                 if$current_User->check_perm'options''edit' && $allow_po_extraction  )
  330.                 // Translator options:
  331.                     ifis_file$po_file ) )
  332.                     {
  333.                         echo "\n\t<td>".'[<a href="b2options.php?tab=regional&amp;action=extract&amp;locale='.$lkey.'" title="'.T_('Extract .po file into b2evo-format').'">'.T_('Extract').'</a>]</td>';
  334.                     }
  335.                 }
  336.             // show message file percentage/extraction
  337.  
  338.             echo '</tr>';
  339.         }
  340.         ?>
  341.         </table>
  342.         <?php if$current_User->check_perm'options''edit' ) )
  343.         {
  344.             ?>
  345.             <p class="center"><a href="b2options.php?tab=regional<?php if$notransext echo '&amp;notransext=1'?>&amp;locale=_new_"><img src="img/new.gif" width="13" height="13" class="middle" alt="" /> <?php echo T_('Create new locale');?></a></p>
  346.             <?php ifisset($l_atleastonefromdb) )
  347.             ?>
  348.                 <p class="center"><a href="b2options.php?tab=regional<?php if$notransext echo '&amp;notransext=1'?>&amp;action=reset" onclick="return confirm('<?php echo /* TRANS: Warning this is a javascript string */ T_('Are you sure you want to reset?');?>')"><img src="img/xross.gif" height="13" width="13" class="middle" alt="" /> <?php echo T_('Reset to defaults (delete database table)');?></a></p>
  349.                 <?php
  350.             }
  351.         }
  352.         ?>
  353.     </fieldset>
  354.  
  355.     <?php if$current_User->check_perm'options''edit' ) )
  356.     {
  357.         form_submit();
  358.     }
  359.     ?>
  360.  
  361. </form>
  362. <?php
  363. }
  364. ?>

Documentation generated on Tue, 20 May 2008 01:55:44 +0200 by phpDocumentor 1.4.2