You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by David Sean Taylor <da...@bluesunrise.com> on 2008/09/03 00:03:01 UTC

velocity decorators and localization

Someone asked me a question about "velocity decorators and  
localization". I responded back directly, but I thought it might also  
be useful to have the response on the Jetspeed User list as well.
...

In your decorator you can access quite a lot of localized current page  
information with calls like:

$element.getTitle($preferedLocale)

Above we are retrieving a title from a menu. All of the folder and  
page model is localized. We have had requests to use resource ids  
instead of storing the localization in the page or folder.
Here is an example of localizing the title of a page:

   <metadata name="title" xml:lang="fr">Bienvenue a Jetspeed</metadata>
   <metadata name="title" xml:lang="ja">Jetspeed 2 へようこそ</ 
metadata>
   <metadata name="title" xml:lang="es">ÁBienvenido a Jetspeed 2!</ 
metadata>
   <metadata name="title" xml:lang="hu">Kšszšnti a Jetspeed 2!</ 
metadata>
   <metadata name="title" xml:lang="zh">欢迎来到Jetspeed 2</ 
metadata>
   <metadata name="title" xml:lang="zh-TW">歡迎來到Jetspeed 2</ 
metadata>
   <metadata name="title" xml:lang="ko">Jetspeed 2 에 오신 것을 환 
영합니다</metadata>

Note that $preferedLocale is made available to you in any decorator,  
see jetspeed_macros.vm:

   #set($preferedLocale = $JS2RequestContext.locale)

You can find out more about PSML (the portlet structured markup  
language), here:

http://portals.apache.org/jetspeed-2/guides/guide-psml.html
http://portals.apache.org/jetspeed-2/guides/guide-menus-declarative-psml.html

You can also localize the location of psml pages using the profiler  
with control directories and two letter language codes.
This is useful if you have completely different layout based on  
language:

http://portals.apache.org/jetspeed-2/guides/guide-profiler.html

You can also localize the location of images by making subdirectories  
in your decorator based on the two letter language code:

	<div id="Logo" style="float:left;"><img src='#GetPageResource("images/ 
${preferedLocale.Language}/logo.gif")'></div>

Finally, if you want to  associate a resource file with a decorator,  
there are some calls available to you on the Decoration interface:

   /**
      * @return the resource bundle locator prefix.
      */
     String getResourceBundleName();

     /**
      * @return the resource bundle for the given Locale and  
RequestContext.
      */
     ResourceBundle getResourceBundle( Locale locale,  
org.apache.jetspeed.request.RequestContext context );

So say in your layout decorator, add this line:

<b>$rootFragment.decoration.getResourceBundle($preferedLocale,  
$ 
JS2RequestContext 
).getString("desktop.pageeditor.dialog.labels.deletepage")</b>

and it should print (for the tigris layout decorator):

"Are you sure you want to delete this page?"

So you can add resources to the decorator under the resources/ 
Messages_(XX).properties

where XX is the language code such as "en" or "fr" or "de"


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by Mansour Al Akeel <ma...@gmail.com>.
Works perfect.
I don't know what was going wrong earlier. This is not critical, but is 
there a way to change the prefix. For example, instead of 
Messages_en.proreties have something like Navigation_en.properties ?


David Sean Taylor wrote:
>
> On Sep 9, 2008, at 9:46 AM, Mansour Al Akeel wrote:
>
>> David, thank you. It's working in tigris. I had to rename the file to 
>> Messages_fr.properties like you said as it had the property in 
>> question. Now, You mentioned that this resource bundle is implemented 
>> only in tigris and blueocean. I looked around and couldn't find were 
>> the code is. I need to implement the resource bundle in my own, and I 
>> need to follow an example. Can you please point me in the right 
>> direction ?
>>
>
> Place your localized resources in the resources directory of your 
> layout decorator with the prefix "Messages_" such as
>
> Messages_en.properties
> Messages_fr.properties
>
> Take the tigris decorator as an example
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by David Sean Taylor <da...@bluesunrise.com>.
On Sep 9, 2008, at 9:46 AM, Mansour Al Akeel wrote:

> David, thank you. It's working in tigris. I had to rename the file  
> to Messages_fr.properties like you said as it had the property in  
> question. Now, You mentioned that this resource bundle is  
> implemented only in tigris and blueocean. I looked around and  
> couldn't find were the code is. I need to implement the resource  
> bundle in my own, and I need to follow an example. Can you please  
> point me in the right direction ?
>

Place your localized resources in the resources directory of your  
layout decorator with the prefix "Messages_" such as

Messages_en.properties
Messages_fr.properties

Take the tigris decorator as an example 

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by Mansour Al Akeel <ma...@gmail.com>.
David, thank you. It's working in tigris. I had to rename the file to 
Messages_fr.properties like you said as it had the property in question. 
Now, You mentioned that this resource bundle is implemented only in 
tigris and blueocean. I looked around and couldn't find were the code 
is. I need to implement the resource bundle in my own, and I need to 
follow an example. Can you please point me in the right direction ?

Thank you.


David Sean Taylor wrote:
>
> On Sep 8, 2008, at 8:47 PM, Mansour Al Akeel wrote:
>
>> David Sean Taylor wrote:
>>>
>>> On Sep 6, 2008, at 1:43 PM, Mansour Al Akeel wrote:
>>>
>>>> Sorry, not enough details in my previous email.
>>>> I have created my own velocity page layout. However, I need to 
>>>> localize it. So I copied the resources directory from the 
>>>> "blueOcean" layout and tried to access the properties in the way 
>>>> you mentioned.
>>>>
>>>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>>>
>>>>
>>>> However, this is not working. The object $rootFragment.decoration. 
>>>> is defined but, 
>>>> $rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext) 
>>>> is not.
>>>>
>>>>
>>>> Can you please let me know if I am doing something wrong?
>>>
>>> Not sure. I tried this with the 2.1.3 installer, with both Tigris 
>>> and Blueocean page decorators. Both cases the expression:
>>>
>>>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>>>
>>>
>>> evaluates to:
>>>
>>> "Are you sure you want to delete this page"
>>>
>> Did you try it with other decorators. I wrote my own decorator from 
>> scratch. I am not sure if there's something else I need to include in 
>> the pages before using the line:
>>
> We only implemented resource bundles for two of the page decorators 
> (tigris, blueocean). You have to follow the examples...placing 
> resources bundles in the resources directory of the decorator
>
>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>
>>
>> I trid to copy the resource directory from Tigris over to my 
>> decorator and tried to use the exact same property, but the page is 
>> breaking with message:
>> "content not available"
>> A quick search shows that this exact property exists only in 
>> tigris/resources/Messages.properties and not in any of the 
>> localization files (ie, Messages_fr.properties ...etc.). So if I 
>> moved this message from the the default properties file 
>> (Messages.properties) to another resource file like 
>> (Messages_en.properties) it will never work. In this case, how can I 
>> do the localization in a decorator ? And before that How can I access 
>> even the default properties file (Messages.properties) from my new 
>> decorator?
>
>
> I don't follow your argument. Why wouldn't it work? Isn't that how 
> resource bundles work, just append the language code and it will 
> correctly load the bundle? Im trying that now for "tigris" .... it works:
>
> cp Messages.properties Messages_fr.properties
>
> replace this line
>
> desktop.pageeditor.dialog.labels.deletepage=Are you sure you want to 
> delete this page?
>
> with this line
>
> desktop.pageeditor.dialog.labels.deletepage=Etes-vous sur de vouloir 
> supprimer cette page?
>
> then save
>
> go back to the page with the <b> test string in the decorator, and use 
> the change language portlet to change the language to "fr" and you 
> will see the new string displayed in the "fr" language
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by David Sean Taylor <da...@bluesunrise.com>.
On Sep 8, 2008, at 8:47 PM, Mansour Al Akeel wrote:

> David Sean Taylor wrote:
>>
>> On Sep 6, 2008, at 1:43 PM, Mansour Al Akeel wrote:
>>
>>> Sorry, not enough details in my previous email.
>>> I have created my own velocity page layout. However, I need to  
>>> localize it. So I copied the resources directory from the  
>>> "blueOcean" layout and tried to access the properties in the way  
>>> you mentioned.
>>>
>>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
>>> $ 
>>> JS2RequestContext 
>>> ).getString("desktop.pageeditor.dialog.labels.deletepage")</b>
>>>
>>> However, this is not working. The object $rootFragment.decoration.  
>>> is defined but,   
>>> $rootFragment.decoration.getResourceBundle($preferedLocale, 
>>> $JS2RequestContext) is not.
>>>
>>>
>>> Can you please let me know if I am doing something wrong?
>>
>> Not sure. I tried this with the 2.1.3 installer, with both Tigris  
>> and Blueocean page decorators. Both cases the expression:
>>
>>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
>>> $ 
>>> JS2RequestContext 
>>> ).getString("desktop.pageeditor.dialog.labels.deletepage")</b>
>>
>> evaluates to:
>>
>> "Are you sure you want to delete this page"
>>
> Did you try it with other decorators. I wrote my own decorator from  
> scratch. I am not sure if there's something else I need to include  
> in the pages before using the line:
>
We only implemented resource bundles for two of the page decorators  
(tigris, blueocean).  You have to follow the examples...placing  
resources bundles in the resources directory of the decorator

> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
> $ 
> JS2RequestContext 
> ).getString("desktop.pageeditor.dialog.labels.deletepage")</b>
>
> I trid to copy the resource directory from Tigris over to my  
> decorator and tried to use the exact same property, but the page is  
> breaking with message:
> "content not available"
> A quick search shows that this exact property exists only in tigris/ 
> resources/Messages.properties and not in any of the localization  
> files (ie, Messages_fr.properties ...etc.). So if I moved this  
> message from the the default properties file (Messages.properties)  
> to another resource file like (Messages_en.properties) it will never  
> work. In this case, how can I do the localization in a decorator ?  
> And before that How can I access even the default properties file  
> (Messages.properties) from my new decorator?


I don't follow your argument. Why wouldn't it work? Isn't that how  
resource bundles work, just append the language code and it will  
correctly load the bundle? Im trying that now for "tigris" .... it  
works:

cp Messages.properties Messages_fr.properties

replace this line

desktop.pageeditor.dialog.labels.deletepage=Are you sure you want to  
delete this page?

with this line

desktop.pageeditor.dialog.labels.deletepage=Etes-vous sur de vouloir  
supprimer cette page?

then save

go back to the page with the <b> test string in the decorator, and use  
the change language portlet to change the language to "fr" and you  
will see the new string displayed in the "fr" language



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by Mansour Al Akeel <ma...@gmail.com>.
David Sean Taylor wrote:
>
> On Sep 6, 2008, at 1:43 PM, Mansour Al Akeel wrote:
>
>> Sorry, not enough details in my previous email.
>> I have created my own velocity page layout. However, I need to 
>> localize it. So I copied the resources directory from the "blueOcean" 
>> layout and tried to access the properties in the way you mentioned.
>>
>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>
>>
>> However, this is not working. The object $rootFragment.decoration. is 
>> defined but,  
>> $rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext) 
>> is not.
>>
>>
>> Can you please let me know if I am doing something wrong?
>
> Not sure. I tried this with the 2.1.3 installer, with both Tigris and 
> Blueocean page decorators. Both cases the expression:
>
>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>
>
> evaluates to:
>
> "Are you sure you want to delete this page"
>
Did you try it with other decorators. I wrote my own decorator from 
scratch. I am not sure if there's something else I need to include in 
the pages before using the line:

<b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b>

I trid to copy the resource directory from Tigris over to my decorator 
and tried to use the exact same property, but the page is breaking with 
message:
"content not available"
A quick search shows that this exact property exists only in 
tigris/resources/Messages.properties and not in any of the localization 
files (ie, Messages_fr.properties ...etc.). So if I moved this message 
from the the default properties file (Messages.properties) to another 
resource file like (Messages_en.properties) it will never work. In this 
case, how can I do the localization in a decorator ? And before that How 
can I access even the default properties file (Messages.properties) from 
my new decorator?

Thank you in advance.




>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by David Sean Taylor <da...@bluesunrise.com>.
On Sep 6, 2008, at 1:43 PM, Mansour Al Akeel wrote:

> Sorry, not enough details in my previous email.
> I have created my own velocity page layout. However, I need to  
> localize it. So I copied the resources directory from the  
> "blueOcean" layout and tried to access the properties in the way you  
> mentioned.
>
> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
> $ 
> JS2RequestContext 
> ).getString("desktop.pageeditor.dialog.labels.deletepage")</b>
>
> However, this is not working. The object $rootFragment.decoration.  
> is defined but,   
> $rootFragment.decoration.getResourceBundle($preferedLocale, 
> $JS2RequestContext) is not.
>
>
> Can you please let me know if I am doing something wrong?

Not sure. I tried this with the 2.1.3 installer, with both Tigris and  
Blueocean page decorators. Both cases the expression:

> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
> $ 
> JS2RequestContext 
> ).getString("desktop.pageeditor.dialog.labels.deletepage")</b>

evaluates to:

"Are you sure you want to delete this page"


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by Mansour Al Akeel <ma...@gmail.com>.
Sorry, not enough details in my previous email.
I have created my own velocity page layout. However, I need to localize 
it. So I copied the resources directory from the "blueOcean" layout and 
tried to access the properties in the way you mentioned.

<b>$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 


However, this is not working. The object $rootFragment.decoration. is 
defined but,  
$rootFragment.decoration.getResourceBundle($preferedLocale,$JS2RequestContext) 
is not.


Can you please let me know if I am doing something wrong?
Thank you.


Mansour Al Akeel wrote:
> David Sean Taylor wrote:
>>
>> Finally, if you want to  associate a resource file with a decorator, 
>> there are some calls available to you on the Decoration interface:
>>
>>   /**
>>      * @return the resource bundle locator prefix.
>>      */
>>     String getResourceBundleName();
>>
>>     /**
>>      * @return the resource bundle for the given Locale and 
>> RequestContext.
>>      */
>>     ResourceBundle getResourceBundle( Locale locale, 
>> org.apache.jetspeed.request.RequestContext context );
>>
>> So say in your layout decorator, add this line:
>>
>> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
>> $JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>>
>>
> I have created a new decorator and I want to use resources. So I 
> created a "resources" directory in the root of the decorator, but I am 
> unable ot access the properties in these files. The decorator is in 
> velocity, How do I get these values ?
>
>> and it should print (for the tigris layout decorator):
>>
>> "Are you sure you want to delete this page?"
>>
>> So you can add resources to the decorator under the 
>> resources/Messages_(XX).properties
>>
>> where XX is the language code such as "en" or "fr" or "de"
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
>> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org


Re: velocity decorators and localization

Posted by Mansour Al Akeel <ma...@gmail.com>.
David Sean Taylor wrote:
>
> Finally, if you want to  associate a resource file with a decorator, 
> there are some calls available to you on the Decoration interface:
>
>   /**
>      * @return the resource bundle locator prefix.
>      */
>     String getResourceBundleName();
>
>     /**
>      * @return the resource bundle for the given Locale and 
> RequestContext.
>      */
>     ResourceBundle getResourceBundle( Locale locale, 
> org.apache.jetspeed.request.RequestContext context );
>
> So say in your layout decorator, add this line:
>
> <b>$rootFragment.decoration.getResourceBundle($preferedLocale, 
> $JS2RequestContext).getString("desktop.pageeditor.dialog.labels.deletepage")</b> 
>
>
I have created a new decorator and I want to use resources. So I created 
a "resources" directory in the root of the decorator, but I am unable ot 
access the properties in these files. The decorator is in velocity, How 
do I get these values ?

> and it should print (for the tigris layout decorator):
>
> "Are you sure you want to delete this page?"
>
> So you can add resources to the decorator under the 
> resources/Messages_(XX).properties
>
> where XX is the language code such as "en" or "fr" or "de"
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
> For additional commands, e-mail: jetspeed-user-help@portals.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-user-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-user-help@portals.apache.org