You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dolf Starreveld <do...@starreveld.com> on 2003/03/22 21:56:13 UTC
Internationalization of string with embedded link?
On a struts based JSP is need to output something like:
To do x, click <here>
<here> means that words needs to be a link. Without using resource
(and internationalization), it would look like:
<P>To do x, click <a href="URL">here</a></P>
Without internationalization 100% OK, it would become:
<P>
<bean:message key="click"/>
<html:link action="/clickAction">here</html:link>
</P>
click=To do x, click
The problem is that this is not fully localizable. In some languages
the word "here" would have to be in a different position. I do not
want to have different JSPs for each locale.
I know I could make a custom tag to do this, but I am hoping somebody
already has a solution to this problem.
--dolf
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Internationalization of string with embedded link?
Posted by Dolf Starreveld <do...@starreveld.com>.
In a mail from 13:44 +1200 3/23/03 Jason Lea wrote:
>Dolf pointed out this doesn't solve the problem due to the use of
>the <html:link> on his jsp page. After looking around I have learnt
>something new :) and have found a solution (using Java Servlet 2.3
>and JavaServer Pages 1.2 eg Tomcat 4+.)
>
>You can use the JSTL & Struts-EL (expression language)...
>
>You can then use these tags:
>
> <c:set var="logoutAction"><bean:message key="logout.action"/></c:set>
>
> <c:set var="clickHere"><html:link forward="homepage"><bean:message
>key="click.here"/></html:link></c:set>
>
> <bean:message key="preferences.test" arg0="${logoutAction}"
>arg1="${clickHere}"/>
That was very helpful. I wanted to do this without any additional tag
libraries, and you got me on the right path. Here is the solution:
In the props file:
msg.full=If you want to x, click {0}
msg.here=here
In the page:
<bean:define id="link">
<html:link forward="/monkey">
<bean:message key="msg.here"/>
</html:link>
</bean:define>
<bean:message key="msg.full" arg0="<%= link %>"/>
--dolf
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Internationalization of string with embedded link?
Posted by Jason Lea <ja...@kumachan.net.nz>.
Dolf pointed out this doesn't solve the problem due to the use of the
<html:link> on his jsp page. After looking around I have learnt
something new :) and have found a solution (using Java Servlet 2.3 and
JavaServer Pages 1.2 eg Tomcat 4+.)
You can use the JSTL & Struts-EL (expression language)...
You can then use these tags:
<c:set var="logoutAction"><bean:message key="logout.action"/></c:set>
<c:set var="clickHere"><html:link forward="homepage"><bean:message
key="click.here"/></html:link></c:set>
<bean:message key="preferences.test" arg0="${logoutAction}"
arg1="${clickHere}"/>
The <c:set> tag puts it's contents into a variable defined by var. So
this allows us to capture the contents of the <html:link> tag so we can
substitute it later.
I have tested it and it actually works. Here is what I had in the
property files:
application.properties:
preferences.test=to {0} click {1}
click.here=here
logout.action=logout
application_ja.properties:
preferences.test=click {1} to {0}
click.here=HERE
logout.action=LOGOUT
and now the output:
default: to logout click <a href="/Homepage.do">here</a>
Japanese locale: click <a href="/Homepage.do">HERE</a> to LOGOUT
I needed to adjust my taglib definitions
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean" %>
and include put the following into my /WEB_INF/lib directory:
struts-el.jar
jstl.jar
standard.jar
and add the following tld's:
c.tld
struts-html-el.tld
struts-bean-el.tld
These are all in Struts 1.1RC1\contrib\struts-el\lib
To read about JSTL V1.0:
http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html
Hope this helps...
Jason Lea
Jason Lea wrote:
> This can be done in Struts using the MessageResources:
>
> Struts Tip #4 - Formatting output with MessageResources
> http://husted.com/struts/tips/004.html
>
> also have a look at the Java Internationalization Tutorial's page
> http://java.sun.com/docs/books/tutorial/i18n/format/messageFormat.html
>
>
> You can use this to specify the format for each language and substitute
> in the correct values at run time.
>
> Jason Lea
>
>
> David M. Karr wrote:
>
>>>>>>> "Dolf" == Dolf Starreveld <do...@starreveld.com> writes:
>>
>>
>>
>> Dolf> On a struts based JSP is need to output something like:
>> Dolf> To do x, click <here>
>> Dolf> <here> means that words needs to be a link. Without using
>> resource (and
>> Dolf> internationalization), it would look like:
>>
>> Dolf> <P>To do x, click <a href="URL">here</a></P>
>>
>> Dolf> Without internationalization 100% OK, it would become:
>> Dolf> <P>
>> Dolf> <bean:message key="click"/>
>> Dolf> <html:link action="/clickAction">here</html:link>
>> Dolf> </P>
>>
>> Dolf> click=To do x, click
>>
>> Dolf> The problem is that this is not fully localizable. In some
>> languages the word
>> Dolf> "here" would have to be in a different position. I do not
>> want to have
>> Dolf> different JSPs for each locale.
>>
>> Dolf> I know I could make a custom tag to do this, but I am hoping
>> somebody already
>> Dolf> has a solution to this problem.
>>
>> It's messy, but you could define your messages that contain links to
>> have three
>> pieces, being "before link", "link", and "after link". You could
>> specify all
>> three in your JSP page in the same way for every locale. Some locales
>> would
>> have all three pieces defined, but some locales might just have the
>> "before
>> link" and "link", and the "after link" would be empty.
>>
>> If your locale-specific arrangements are any more complicated than
>> this, then
>> you should use different JSP pages for each locale. You might be able
>> to get
>> away with using a smaller include file for just the locale-specific
>> part, and
>> have the rest of the page just use resources and simple tricks like as
>> described above.
>>
>
>
--
Jason Lea
Email: jason@kumachan.net.nz
Phone/Fax: +64 3 381 2907
Mobile: +64 21 040 2708
Address: 9a Tabart Street, Christchurch, New Zealand
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Internationalization of string with embedded link?
Posted by Jason Lea <ja...@kumachan.net.nz>.
This can be done in Struts using the MessageResources:
Struts Tip #4 - Formatting output with MessageResources
http://husted.com/struts/tips/004.html
also have a look at the Java Internationalization Tutorial's page
http://java.sun.com/docs/books/tutorial/i18n/format/messageFormat.html
You can use this to specify the format for each language and substitute
in the correct values at run time.
Jason Lea
David M. Karr wrote:
>>>>>>"Dolf" == Dolf Starreveld <do...@starreveld.com> writes:
>
>
> Dolf> On a struts based JSP is need to output something like:
> Dolf> To do x, click <here>
> Dolf> <here> means that words needs to be a link. Without using resource (and
> Dolf> internationalization), it would look like:
>
> Dolf> <P>To do x, click <a href="URL">here</a></P>
>
> Dolf> Without internationalization 100% OK, it would become:
> Dolf> <P>
> Dolf> <bean:message key="click"/>
> Dolf> <html:link action="/clickAction">here</html:link>
> Dolf> </P>
>
> Dolf> click=To do x, click
>
> Dolf> The problem is that this is not fully localizable. In some languages the word
> Dolf> "here" would have to be in a different position. I do not want to have
> Dolf> different JSPs for each locale.
>
> Dolf> I know I could make a custom tag to do this, but I am hoping somebody already
> Dolf> has a solution to this problem.
>
> It's messy, but you could define your messages that contain links to have three
> pieces, being "before link", "link", and "after link". You could specify all
> three in your JSP page in the same way for every locale. Some locales would
> have all three pieces defined, but some locales might just have the "before
> link" and "link", and the "after link" would be empty.
>
> If your locale-specific arrangements are any more complicated than this, then
> you should use different JSP pages for each locale. You might be able to get
> away with using a smaller include file for just the locale-specific part, and
> have the rest of the page just use resources and simple tricks like as
> described above.
>
--
Jason Lea
Email: jason@kumachan.net.nz
Phone/Fax: +64 3 381 2907
Mobile: +64 21 040 2708
Address: 9a Tabart Street, Christchurch, New Zealand
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Internationalization of string with embedded link?
Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Dolf" == Dolf Starreveld <do...@starreveld.com> writes:
Dolf> On a struts based JSP is need to output something like:
Dolf> To do x, click <here>
Dolf> <here> means that words needs to be a link. Without using resource (and
Dolf> internationalization), it would look like:
Dolf> <P>To do x, click <a href="URL">here</a></P>
Dolf> Without internationalization 100% OK, it would become:
Dolf> <P>
Dolf> <bean:message key="click"/>
Dolf> <html:link action="/clickAction">here</html:link>
Dolf> </P>
Dolf> click=To do x, click
Dolf> The problem is that this is not fully localizable. In some languages the word
Dolf> "here" would have to be in a different position. I do not want to have
Dolf> different JSPs for each locale.
Dolf> I know I could make a custom tag to do this, but I am hoping somebody already
Dolf> has a solution to this problem.
It's messy, but you could define your messages that contain links to have three
pieces, being "before link", "link", and "after link". You could specify all
three in your JSP page in the same way for every locale. Some locales would
have all three pieces defined, but some locales might just have the "before
link" and "link", and the "after link" would be empty.
If your locale-specific arrangements are any more complicated than this, then
you should use different JSP pages for each locale. You might be able to get
away with using a smaller include file for just the locale-specific part, and
have the rest of the page just use resources and simple tricks like as
described above.
--
===================================================================
David M. Karr ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net ; SCJP; SCWCD
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org