Stripes

Localize title attribute for Stripes tags.

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Trivial Trivial
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: Tag Library
  • Labels:
    None
  • Environment:
    Mac OS X 10.4.10, Java 1.5.0_07

Description

It would be nice if Stripes tag localizes its title.
So that we can write

<stripes:text name="user.address" title="user.address.title" />

instead of

<fmt:message var="userAddressTitle" key="user.address.title" />
<stripes:text name="user.address" title="${userAddressTitle}"/>

  1. STS433_PATCH_VERSION_2.txt
    12/Nov/10 12:11 AM
    2 kB
    Nikolaos
  2. STS433_PATCH_VERSION_FIXED_3.txt
    28/Nov/10 12:55 AM
    1 kB
    Nikolaos
  3. STS-433.patch
    14/Nov/07 1:04 AM
    3 kB
    Iwao AVE!

Activity

Hide
Iwao AVE! added a comment - 14/Nov/07 1:04 AM

Attached is a trivial patch to achieve title localization.
For input tags, it takes the action path into account.
If no corresponding resource string is found, it outputs the original title value.

Show
Iwao AVE! added a comment - 14/Nov/07 1:04 AM Attached is a trivial patch to achieve title localization. For input tags, it takes the action path into account. If no corresponding resource string is found, it outputs the original title value.
Hide
Reder Tseng added a comment - 11/Dec/09 11:08 AM

Will this feature be added to the project in future release?

It's some what essential in localization since the title should be changed when changing language.

Show
Reder Tseng added a comment - 11/Dec/09 11:08 AM Will this feature be added to the project in future release? It's some what essential in localization since the title should be changed when changing language.
Hide
Frederic Daoud added a comment - 11/Dec/09 3:17 PM

It is a nice to have, but the proposed solution does not indicate how to differentiate a resource bundle lookup from a plain text title. In other words, given:

<stripes:text name="user.address" title="hello" />

How do you know whether I want to look up "hello" in the resource bundle or I want the title to just be "hello"?

Also, I would not call this an essential issue, since you already have a straightforward way to change the title when changing language: just use a <fmt> tag as documented above.

Show
Frederic Daoud added a comment - 11/Dec/09 3:17 PM It is a nice to have, but the proposed solution does not indicate how to differentiate a resource bundle lookup from a plain text title. In other words, given: <stripes:text name="user.address" title="hello" /> How do you know whether I want to look up "hello" in the resource bundle or I want the title to just be "hello"? Also, I would not call this an essential issue, since you already have a straightforward way to change the title when changing language: just use a <fmt> tag as documented above.
Hide
John Newman added a comment - 11/Dec/09 3:53 PM

Freddy, I completely agree with you. I don't think the stripes tags should be doing ANY localization by default. If you want to localize, use <fmt> or turn on a setting to allow the stripes tags to do it.

http://www.stripesframework.org/jira/browse/STS-683

Show
John Newman added a comment - 11/Dec/09 3:53 PM Freddy, I completely agree with you. I don't think the stripes tags should be doing ANY localization by default. If you want to localize, use <fmt> or turn on a setting to allow the stripes tags to do it. http://www.stripesframework.org/jira/browse/STS-683
Hide
Reder Tseng added a comment - 11/Dec/09 10:44 PM

The Struts 1 way is adding an attribute "titleKey" to tags for this kind of localization.

Or using the way similar to <stripes:images />, which is finding the key such as actionFQN.inputName.[src|alt]. Then the title may be designed as actionFQN.inputName.title.

The two way about could solve the problem you metioned.

Show
Reder Tseng added a comment - 11/Dec/09 10:44 PM The Struts 1 way is adding an attribute "titleKey" to tags for this kind of localization. Or using the way similar to <stripes:images />, which is finding the key such as actionFQN.inputName.[src|alt]. Then the title may be designed as actionFQN.inputName.title. The two way about could solve the problem you metioned.
Hide
Iwao AVE! added a comment - 14/Dec/09 8:32 AM

Thanks for the comments.

To Reder,

It wouldn't be hard for you to apply the patch locally.
If you have any difficulty with the patch, please add a comment.

  1. In case you want the feature to be included in the official release, voting for the bug might help.

To Freddy,

With the patch, Stripes tries to localize the string at first, and if it fails (no resource string is found in StripesResources) the original string 'hello' is output. This would be the same behavior for the 'name' attribute of most stripes tags.

  1. Although it is a trivial issue (as the priority suggests), it makes a big difference when you have to do it in a relatively large webapp
Show
Iwao AVE! added a comment - 14/Dec/09 8:32 AM Thanks for the comments. To Reder, It wouldn't be hard for you to apply the patch locally. If you have any difficulty with the patch, please add a comment.
  1. In case you want the feature to be included in the official release, voting for the bug might help.
To Freddy, With the patch, Stripes tries to localize the string at first, and if it fails (no resource string is found in StripesResources) the original string 'hello' is output. This would be the same behavior for the 'name' attribute of most stripes tags.
  1. Although it is a trivial issue (as the priority suggests), it makes a big difference when you have to do it in a relatively large webapp
Hide
Nikolaos added a comment - 11/Nov/10 1:15 PM

I have to say I agree with Iwao that doing the following over and over again is really taxing for anyone that is building a large Web app that is heavily localized.
<fmt:message var="userAddressTitle" key="user.address.title" />
<stripes:text name="user.address" title="${userAddressTitle}"/>

e.g. writing 2 lines for every 1 line of form input or hyperlink may seem like an acceptable workaround but actually is quite frustrating and unnecessarily tedius... .

The "title" attribute is very useful for a number of reasons (tooltip, SEO, etc...) on not only "input" tags but also on "a" tags.

I would highly recommend that Stripes "input" and "a" tags are augmented to work the way Reder described which is to basically use the name of the tag and do a lookup for ".title" in the resource bundle (assuming the value is not provided). This would not only align to how Stripes handles localization for other tags like the "img" tag where it does a look up for ".src" and ".alt" attributes if they are not provided but this also addresses Freddy's concern of how to differentiate between a string being a value vs. a key for lookup.

Localization may not be a highlight for all projects but where its required it needs to be quite thoroughly worked into the web framework.

--Nikolaos

Show
Nikolaos added a comment - 11/Nov/10 1:15 PM I have to say I agree with Iwao that doing the following over and over again is really taxing for anyone that is building a large Web app that is heavily localized. <fmt:message var="userAddressTitle" key="user.address.title" /> <stripes:text name="user.address" title="${userAddressTitle}"/> e.g. writing 2 lines for every 1 line of form input or hyperlink may seem like an acceptable workaround but actually is quite frustrating and unnecessarily tedius... . The "title" attribute is very useful for a number of reasons (tooltip, SEO, etc...) on not only "input" tags but also on "a" tags. I would highly recommend that Stripes "input" and "a" tags are augmented to work the way Reder described which is to basically use the name of the tag and do a lookup for ".title" in the resource bundle (assuming the value is not provided). This would not only align to how Stripes handles localization for other tags like the "img" tag where it does a look up for ".src" and ".alt" attributes if they are not provided but this also addresses Freddy's concern of how to differentiate between a string being a value vs. a key for lookup. Localization may not be a highlight for all projects but where its required it needs to be quite thoroughly worked into the web framework. --Nikolaos
Hide
Nikolaos added a comment - 12/Nov/10 12:08 AM

I looked over Iwao's patch and as it turns out there is a really simple way to add the desired functionality in a very clean way.

Essentially the superclass InputTagSupport in its doEndTag method after calling:
int result = doEndInputTag();

Need simply do the following:
String name = getAttributes().get("name");
if (name != null) { // Skip title lookup if no name to lookup against
String title = getLocalizedFieldName(name + ".title");
if (title != null) { setTitle(title); }
}

And then add the following at the bottom:
public void setTitle(String title) { set("title", title); }
public String getTitle() { return get("title"); }

All of this has the net effect of aligning to how Stripes build other localized attributes like the "alt" attribute for the "image" tag.

And the best of both worlds are available. If a hardcoded value for title is provided in the input tag then it is used otherwise if the title attribute does not exist then Stripes uses the same mechanism of FQ-name and non-FQ-name to lookup the value in the resource bundle. If the title attribute is neither hard coded or provided in the resource bundle then no title attribute is included in the tag.

I'll attach the full patch file as STS433_PATCH_VERSION_2.txt

--Nikolaos

Show
Nikolaos added a comment - 12/Nov/10 12:08 AM I looked over Iwao's patch and as it turns out there is a really simple way to add the desired functionality in a very clean way. Essentially the superclass InputTagSupport in its doEndTag method after calling: int result = doEndInputTag(); Need simply do the following: String name = getAttributes().get("name"); if (name != null) { // Skip title lookup if no name to lookup against String title = getLocalizedFieldName(name + ".title"); if (title != null) { setTitle(title); } } And then add the following at the bottom: public void setTitle(String title) { set("title", title); } public String getTitle() { return get("title"); } All of this has the net effect of aligning to how Stripes build other localized attributes like the "alt" attribute for the "image" tag. And the best of both worlds are available. If a hardcoded value for title is provided in the input tag then it is used otherwise if the title attribute does not exist then Stripes uses the same mechanism of FQ-name and non-FQ-name to lookup the value in the resource bundle. If the title attribute is neither hard coded or provided in the resource bundle then no title attribute is included in the tag. I'll attach the full patch file as STS433_PATCH_VERSION_2.txt --Nikolaos
Hide
Nikolaos added a comment - 12/Nov/10 12:11 AM

The patch is super simple and extremely straight forward leveraging meshing seamlessly into Stripes.

--Nikolaos

Show
Nikolaos added a comment - 12/Nov/10 12:11 AM The patch is super simple and extremely straight forward leveraging meshing seamlessly into Stripes. --Nikolaos
Hide
Nikolaos added a comment - 27/Nov/10 11:38 PM

After some more extensive testing I found 2 issues in the patch that have now been corrected and will be uploaded in a new patch (to follow):

1) I had been doing the injection in doEndTag which resulted in some funky results... doStartTag is the correct place

2) It's a little odd that Stripes considers a HTML Label to be a subclass of InputTagSupport however in any event we don't want titles appearing on labels so the new code needs to exclude adding title to labels via a simple instanceof check.

The details to be included in the next patch STS433_PATCH_VERSION_2.txt however to reiterate essentially this allows one to change:
<fmt:message var="userAddressTitle" key="user.address.title" />
<stripes:text name="user.address" title="${userAddressTitle}"/>

To:
<stripes:text name="user.address"/>

And title attribute with localized text will get rendered IFF it is found in the Stripes resource bundle. Save A LOT of boilerplate JSP coding!!!!!

I'll attach the full patch file as STS433_PATCH_VERSION_2.txt

--Nikolaos

Show
Nikolaos added a comment - 27/Nov/10 11:38 PM After some more extensive testing I found 2 issues in the patch that have now been corrected and will be uploaded in a new patch (to follow): 1) I had been doing the injection in doEndTag which resulted in some funky results... doStartTag is the correct place 2) It's a little odd that Stripes considers a HTML Label to be a subclass of InputTagSupport however in any event we don't want titles appearing on labels so the new code needs to exclude adding title to labels via a simple instanceof check. The details to be included in the next patch STS433_PATCH_VERSION_2.txt however to reiterate essentially this allows one to change: <fmt:message var="userAddressTitle" key="user.address.title" /> <stripes:text name="user.address" title="${userAddressTitle}"/> To: <stripes:text name="user.address"/> And title attribute with localized text will get rendered IFF it is found in the Stripes resource bundle. Save A LOT of boilerplate JSP coding!!!!! I'll attach the full patch file as STS433_PATCH_VERSION_2.txt --Nikolaos
Hide
Nikolaos added a comment - 28/Nov/10 12:28 AM

CORRECTION: Updated patch file attached as STS433_PATCH_VERSION_FIXED_3.txt

Show
Nikolaos added a comment - 28/Nov/10 12:28 AM CORRECTION: Updated patch file attached as STS433_PATCH_VERSION_FIXED_3.txt

People

Vote (0)
Watch (1)

Dates

  • Created:
    14/Nov/07 12:49 AM
    Updated:
    28/Nov/10 12:55 AM