You are viewing the PKP Support Forum | PKP Home Wiki

Reordering interface text for localization

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

Reordering interface text for localization

Postby mark » Thu Oct 09, 2008 2:22 am

I'm decided to add some date functionality to OJS but have encountered a problem when localizing the presentation of dates for the interface.

I store dates as YYYY-MM-DD and want it to present as Month Name DD, YYYY (e.g., April 5, 2003). For French this would be Avril 4, 2003. To do this, a first guess would be add MonthNumber-to-MonthName conversion funcationality in the locale.xml file:

in the locale.xml file is
Code: Select all
        <message key="month.number.1">Jan</message>
        <message key="month.number.2">Feb</message>
        <message key="month.number.3">Mar</message>
        <message key="month.number.4">Apr</message>
        <message key="month.number.5">May</message>
        <message key="month.number.6">Jun</message>
        <message key="month.number.7">Jul</message>
        <message key="month.number.8">Aug</message>
        <message key="month.number.9">Sep</message>
        <message key="month.number.10">Oct</message>
        <message key="month.number.11">Nov</message>
        <message key="month.number.12">Dec</message>

And then in the application layer tease the YYYY and MM and DD from the date,
Code: Select all
$date = 5;
$month = 4;
$year = 2003;
$templateManager->assign('date', $date);
$templateManager->assign('year', $year);
$templateManager->assign('month', $month);

And in the template file, do the following:
Code: Select all
{translate key="month.number.$month"} {$date}, {$year} 

This works, so all is fine to this point, but there is (or may be) a glitch. What if in some countries/locally, there is preference for date to be in the form: 2008-April-05 or 5 April 2008? At first glance it seems smarty templates and the translate routine of OJS effectively hard code the format. I may be pushing the translate routine beyond its original design. But has anyone encountered something like that (i.e., localization that requires not simply a translate-lookup but an actually reordering of interface text)?

Posts: 31
Joined: Fri Jul 11, 2008 10:57 am

Re: Reordering interface text for localization

Postby jmacgreg » Thu Oct 09, 2008 11:14 am

Hi Mark,

Your config.inc.php has a section on how to display short and long date formats, which you may want to take a look at. There's a good breakdown of date formatting here: viewtopic.php?f=13&t=3511&p=13213&hilit=date+php#p13213 -- it deals with delivering dates in different formats by manipulating config.inc.php, and also talks about how different locales are handled by PHP's formatting tools.

Posts: 4191
Joined: Tue Feb 14, 2006 10:50 am

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest