[pLog-svn] r732 - in plog/trunk: class/locale locale templates/admin
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Tue Jan 11 21:23:21 GMT 2005
Author: oscar
Date: 2005-01-11 21:23:20 +0000 (Tue, 11 Jan 2005)
New Revision: 732
Modified:
plog/trunk/class/locale/locale.class.php
plog/trunk/locale/locale_en_UK.php
plog/trunk/templates/admin/dashboard.template
plog/trunk/templates/admin/editcomments.template
plog/trunk/templates/admin/editposts.template
plog/trunk/templates/admin/edittrackbacks.template
plog/trunk/templates/admin/poststats.template
plog/trunk/templates/admin/statistics.template
Log:
added support for localizable locales. Now each locale can provide its own format for locales so that users can specify day/month/year or month/day/year in the locale file via the $messages["date_format"] string. It takes the same parameters that Locale::formatDate() and if it does not exist, "%d/%m/%Y %H:%M" is the default one.
Locale::formatDate has been modified so that the second parameter (the format) is now optional. If not present, the locale-supplied date format will be used.
Modified: plog/trunk/class/locale/locale.class.php
===================================================================
--- plog/trunk/class/locale/locale.class.php 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/class/locale/locale.class.php 2005-01-11 21:23:20 UTC (rev 732)
@@ -8,6 +8,11 @@
include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
define( "DEFAULT_LOCALE_FOLDER", PLOG_CLASS_PATH . "locale" );
+
+ /**
+ * default locale format that will be used if none available
+ */
+ define( "DEFAULT_LOCALE_FORMAT", "%d/%m/%Y %H:%M" );
/**
* Class used to localize messages and things such as dates and numbers.
@@ -42,6 +47,8 @@
var $_code; // our ISO locale code, eg. es_ES, en_UK, etc
var $_messages;
var $_charset;
+ var $_description;
+ var $_dateFormat;
/**
* Constructor.
@@ -63,11 +70,8 @@
$this->_code = $code;
- $this->_loadLocaleFile();
+ $this->_loadLocaleInfo();
- $this->_charset = $this->_messages["encoding"];
- $this->_direction = $this->_messages["direction"];
-
if( $this->_charset == "" )
$this->_charset = DEFAULT_ENCODING;
}
@@ -84,6 +88,30 @@
$this->_messages = $messages;
}
+
+ /**
+ * @private
+ * Loads the locale file, extracts the information needed and frees the used memory
+ */
+ function _loadLocaleInfo()
+ {
+ // load the locale into $this->_messages
+ $this->_loadLocaleFile();
+
+ // get the info that we need
+ $this->_description = $this->_messages["locale_description"];
+ $this->_charset = $this->_messages["encoding"];
+ $this->_direction = $this->_messages["direction"];
+ $this->_dateFormat = $this->_messages["date_format"];
+ // use a default one if none available
+ if( $this->_dateFormat == "" )
+ $this->_dateFormat = DEFAULT_LOCALE_FORMAT;
+
+ unset( $this->_messages );
+ $this->_messages = NULL;
+
+ return( true );
+ }
/**
* Returns the character encoding method used by the current locale file. It has to be a valid
@@ -119,7 +147,7 @@
*/
function getDescription()
{
- return $this->_messages["locale_description"];
+ return( $this->_description );
}
/**
@@ -156,6 +184,10 @@
*/
function getString( $id )
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
$string = $this->_messages[ $id ];
if( $string == "" )
$string = $id;
@@ -173,6 +205,10 @@
*/
function getStrings()
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
return $this->_messages;
}
@@ -277,6 +313,10 @@
*/
function getMonthNames()
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
return $this->_messages["months"];
}
@@ -288,6 +328,10 @@
*/
function getDayNames()
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
return $this->_messages["days"];
}
@@ -299,6 +343,10 @@
*/
function getDayNamesShort()
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
return $this->_messages["daysshort"];
}
@@ -385,8 +433,12 @@
* <li>%D cardinal representation of the day</li>
* </ul>
*/
- function formatDate( $timeStamp, $format )
+ function formatDate( $timeStamp, $format = null )
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
// timestamp only returns the values in english, so we should translate
// them before using
$monthId = (int)$timeStamp->getMonth();
@@ -395,6 +447,10 @@
// and the same for the weekdays
$weekdayId = $timeStamp->getWeekdayId();
$weekday = $this->_messages["days"][$weekdayId];
+
+ // if the user did not specify a format, let's use the default one
+ if( $format == null )
+ $format = $this->_dateFormat;
// now we can continue normally
$values["%a"] = substr($weekday, 0, 2 );
@@ -430,6 +486,10 @@
*/
function mergeLocale( $locale )
{
+ // load the file if it hadn't been loaded yet
+ if( !is_array($this->_messages))
+ $this->_loadLocaleFile();
+
$this->_messages = array_merge( $this->_messages, $locale->getStrings());
return true;
Modified: plog/trunk/locale/locale_en_UK.php
===================================================================
--- plog/trunk/locale/locale_en_UK.php 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/locale/locale_en_UK.php 2005-01-11 21:23:20 UTC (rev 732)
@@ -2,6 +2,9 @@
// set this to the encoding that should be used to display the pages correctly
$messages["encoding"] = "iso-8859-1";
$messages["locale_description"] = "English locale file for pLog";
+// locale format, see Locale::formatDate for more information
+$messages["date_format"] = "%d/%m/%Y %H:%M";
+
// days of the week
$messages["days"] = Array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
// -- compatibility, do not touch -- //
Modified: plog/trunk/templates/admin/dashboard.template
===================================================================
--- plog/trunk/templates/admin/dashboard.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/dashboard.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -39,7 +39,7 @@
{/if}
{$locale->tr("in")} <a href="{$url->postPermalink($article)}">{$article->getTopic()}</a>
{assign var=commentDate value=$comment->getDateObject()}
- {$locale->formatDate($commentDate,"%d/%m/%Y %H:%M")}<br/>
+ {$locale->formatDate($commentDate)}<br/>
{/foreach}
<br/>
Modified: plog/trunk/templates/admin/editcomments.template
===================================================================
--- plog/trunk/templates/admin/editcomments.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/editcomments.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -71,7 +71,7 @@
</td>
<td>
{assign var=date value=$comment->getDateObject()}
- {$locale->formatDate($date,"%d/%m/%Y %H:%M")}
+ {$locale->formatDate($date)}
</td>
<td>
{foreach from=$commentstatus key=name item=status}
Modified: plog/trunk/templates/admin/editposts.template
===================================================================
--- plog/trunk/templates/admin/editposts.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/editposts.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -102,7 +102,7 @@
</td>
<td>
{assign var=date value=$post->getDateObject()}
- {$locale->formatDate($date,"%d/%m/%Y %H:%M")}
+ {$locale->formatDate($date)}
</td>
<td>
{assign var=owner value=$post->getUserInfo()}
Modified: plog/trunk/templates/admin/edittrackbacks.template
===================================================================
--- plog/trunk/templates/admin/edittrackbacks.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/edittrackbacks.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -39,7 +39,7 @@
</td>
<td>
{assign var=date value=$trackback->getDateObject()}
- {$locale->formatDate($date,"%d/%m/%Y %H:%M")}
+ {$locale->formatDate($date)}
</td>
<td>
<div class="list_action_button">
Modified: plog/trunk/templates/admin/poststats.template
===================================================================
--- plog/trunk/templates/admin/poststats.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/poststats.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -34,7 +34,7 @@
</td>
<td>
{assign var=date value=$referrer->getDateObject()}
- {$locale->formatDate($date,"%d/%m/%Y %H:%M")}
+ {$locale->formatDate($date)}
</td>
<td>
<div class="list_action_button">
Modified: plog/trunk/templates/admin/statistics.template
===================================================================
--- plog/trunk/templates/admin/statistics.template 2005-01-11 21:08:17 UTC (rev 731)
+++ plog/trunk/templates/admin/statistics.template 2005-01-11 21:23:20 UTC (rev 732)
@@ -32,7 +32,7 @@
</td>
<td>
{assign var=date value=$referrer->getDateObject()}
- {$locale->formatDate($date,"%d/%m/%Y %H:%M")}
+ {$locale->formatDate($date)}
</td>
<td>
<div class="list_action_button">
More information about the pLog-svn
mailing list