Re: S2 - Need advice with Localization

2008-09-18 Thread Laurie Harper

bob fuller wrote:


I am trying to Localize a dynamic message and would like some advice as to how 
I should go about it. My main goal is to keep the message itself as 'intact' as 
possible in my package.properties, doing this will (hopefully) speed up 
translation by an interpreter. Goals after that are to use the Struts 2 
software correctly and cleanly and also keep the amount of work needed to a 
minimum.

Here's the dynamic message that I want to localize...

Welcome to SEA (Seattle International Airport) - Additional information about 
Hotels, Entertainment, Transportation, and Dining is available.

The "SEA" & "Seattle International Airport" parts of the message are dynamic. Also, the following words are dynamic 
links - "Hotels", "Entertainment", "Transportation", "Dining". Here is what the message looks like in 
my package.properties file...

welcomeMessage=Welcome to {0} ({1}) - Additional information about 
{2}Hotels{3}, {4}Entertainment{5}, {6}Transportation{7}, and {8}Dining{9} is 
available.

In my JSP I do this to render the single line of text (I didn't verify that it's syntax correct)... 


http://www.somewebsite.com/hotels.do";>http://www.somewebsite.com/entertainment.do";>http://www.somewebsite.com/transportation.do";>http://www.somewebsite.com/dining.do";>  ">  ">  
value="%{urlTransportation}"/>">  ">


OK. Thanks for getting this far! I am concerned about the amount of JSP that is 
needed for my single dynamic message. Is that just how it is? Or perhaps my 
approach is flawed? Does anyone have any advice or perhaps a tutorial 
suggestion that provides examples 'advanced' localization examples?


There are some obvious clean-ups you could do, such as: not requiring a 
separate s:param for the 'a' start-tag and end-tag (which seems error 
prone); factoring out the URL construction logic so you don't have to 
repeat the airportCode bit for each one; etc. That said, I would suggest 
considering a different approach.


1) create a custom tag / .tag file / custom struts tag to fully 
encapsulate all that presentation logic, perhaps using a single 
key/identifier to resolve all the dynamic bits;


2) creating a POJO helper class that knows how to do the dynamic data 
lookup and complex message construction, exposing an instance of it via 
a getter in your action and keeping the JSP code as simple as 



You didn't say *how* the various parts of the message are dynamic 
(loaded from a resource bundle? loaded from a database? hard-coded with 
different values in different JSPs?), so it's hard to be any more 
specific than that. And I'm sure there are other possible approaches I 
haven't thought of ;-)


L.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: S2 - Need advice with Localization

2008-09-18 Thread Paweł Wielgus
Hi Bob,
i would do it like that:

welcomeMessage=Welcome to {0} - Additional information about {1} is available.

then in jsp


and in action
public String getWelcomeMessage() {
 return getText("welcomeMessage", varFromDatabase1, varFromDatabase2);
}

I asume that name and second parameter are constructed somehow
(database or configuration).
I'm not saying that this is most proper, but it will do the job.

Best greetings,
Paweł Wielgus.



2008/9/18 bob fuller <[EMAIL PROTECTED]>:
>
>
> I am trying to Localize a dynamic message and would like some advice as to 
> how I should go about it. My main goal is to keep the message itself as 
> 'intact' as possible in my package.properties, doing this will (hopefully) 
> speed up translation by an interpreter. Goals after that are to use the 
> Struts 2 software correctly and cleanly and also keep the amount of work 
> needed to a minimum.
>
> Here's the dynamic message that I want to localize...
>
> Welcome to SEA (Seattle International Airport) - Additional information about 
> Hotels, Entertainment, Transportation, and Dining is available.
>
> The "SEA" & "Seattle International Airport" parts of the message are dynamic. 
> Also, the following words are dynamic links - "Hotels", "Entertainment", 
> "Transportation", "Dining". Here is what the message looks like in my 
> package.properties file...
>
> welcomeMessage=Welcome to {0} ({1}) - Additional information about 
> {2}Hotels{3}, {4}Entertainment{5}, {6}Transportation{7}, and {8}Dining{9} is 
> available.
>
> In my JSP I do this to render the single line of text (I didn't verify that 
> it's syntax correct)...
>
> http://www.somewebsite.com/hotels.do";>   name="airportCode">  
>  value="http://www.somewebsite.com/entertainment.do";>   name="airportCode">  
>  value="http://www.somewebsite.com/transportation.do";>   name="airportCode">  
>  value="http://www.somewebsite.com/dining.do";> 
> name="welcomeMessage"> value="airport.name"/>  ">  
> "> value="''"/>  ">  
> ">
> 
>
> OK. Thanks for getting this far! I am concerned about the amount of JSP that 
> is needed for my single dynamic message. Is that just how it is? Or perhaps 
> my approach is flawed? Does anyone have any advice or perhaps a tutorial 
> suggestion that provides examples 'advanced' localization examples?
>
> Thanks.
> _
> Get more out of the Web. Learn 10 hidden secrets of Windows Live.
> http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!5295.entry?ocid=TXT_TAGLM_WL_domore_092008