On Tue, 20 Mar 2001, Maya Muchnik wrote:

> Craig,
> 
> Can I ask you on an example to be sure, that it is correct.
> My images are under images directory from root application dir. So, I can put the
> following statements:
> (in a property file :
> message.key=images
> a.image=a.gif
> a.image.dir=images/a.gif
> )
> 
> <html:image pageKey="message.key"/>
> ...
> <html:image src="a.gif"/>
> ...
> 
> Can I put a.gif into the property file too, and have the second statement as
> this:
> <html:image src="a.image"/>
> Or I can have
> <html:image srcKey="a.image.dir"/>
> 

The assumption behind this new facility is that you need to
internationalize your images as well as your messages.  Perhaps, for
example, you've created image buttons and the text of those buttons needs
to be different depending on the user's locale.

Now, let's take Maya's example, and say that our images are stored in an
"images" directory (relative to the context path of this
application).  Now, in my application resources for English, I might have:

        image.a=/images/a_en.gif
        image.b=/images/b.gif

while in my application resources for French, I might have:

        image.a=/images.a_fr.gif
        image.b=/images.b.gif

Note that -- with these settings -- I'm using a different GIF file for the
"a" image, but (currently) sharing the "b" image.  Now, I can create a
single JSP page that grabs the correct version of each image:

        <html:image pageKey="image.a"/>
        <html:image pageKey="image.b"/>

(When you use the "pageKey" attribute, your paths have to be context
relative and start with a slash, just like all the paths in
struts-config.xml.)

Note one added advantage of this approach.  Currently, we're sharing the
"b" image because it didn't need to be internationalized.  Now, you decide
that you really do want to make it different.  All you have to do is:
* Create the new "/images/b_en.gif" and "/images/b_fr.gif" image files
* Change the two lines in your application resources
* Restart your app, with no change to any JSP page that uses
  those images.

Pretty slick, huh?  :-)

> Thanks,
> 
> Maya
> 

Craig


> "Craig R. McClanahan" wrote:
> 
> > There was a recent addition to the <html:image> and <html:img> tags to
> > support internationalized images elegantly.
> >
> > Previously, you had to use the "src" attribute to specify the URI of your
> > image.  If you needed different images for each language, you had to use a
> > scriptlet expression of some sort to calculate them.
> >
> > Now, you can specify a message key (to be looked up in your application
> > resources) instead:
> >
> >         <html:image srcKey="message.key"/>
> >
> > where "message.key" identifies the path to this image from your
> > application resources.
> >
> > If you want to use context-relative paths everywhere, use:
> >
> >         <html:image pageKey="message.key"/>
> >
> > instead.
> >
> >
> >
> > Craig
> 
> 

Reply via email to