kinyelo / vosao

Automatically exported from code.google.com/p/vosao
GNU Lesser General Public License v2.1
1 stars 2 forks source link

Change velocity datetool to use the current page language when formatting dates #365

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Use $date.format('medium',$p.publishDate) in pages with different languages, 
for example de and en

What is the expected output? What do you see instead?
4/5/10 12:00 AM for language en
5.4.10 0:00 for language de

instead the output for language de is the same as for language en.

Original issue reported on code.google.com by Emo...@gmail.com on 16 Oct 2010 at 10:47

GoogleCodeExporter commented 9 years ago
I looked sources and found one variant to achieve 'date localization' inside 
template.

\trunk\kernel\src\main\java\org\vosao\business\impl\PageBusinessImpl.java

public VelocityContext createContext(final String languageCode) {...
line ~ 189:
.....
    context.put("language", language);
        context.put("locale", new Locale(language.getCode())); //!! ADD Locale to Velocity context using 'language code'
.....

Now you can tweak Velocity template like:
Change current code from:
$date.format('MMM', $page.publishDate)
to:
$date.format('MMM', $page.publishDate, $locale)

-----
from
date.format('medium_time', $page.modDate)
to
date.format('medium_time', $page.modDate, $locale)

Works fine for me. Of course that patch doesn't fix all possible cases. There 
is no ability to make Locale using more then one parameter now, like 
Locale("String language, String country).

Original comment by bland...@gmail.com on 2 Nov 2010 at 12:05

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r932.

Original comment by kinyelo@gmail.com on 26 Nov 2010 at 5:31