Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Localized message output improvements #517

Closed
glassfishrobot opened this issue Dec 24, 2008 · 14 comments
Closed

Localized message output improvements #517

glassfishrobot opened this issue Dec 24, 2008 · 14 comments

Comments

@glassfishrobot
Copy link

The JSF 1.2 approach to language localisation using a message bundle
does not easily support several common cases.

1. Parameterised message used in an attribute value:

<h:commandLink value="Delete #

{name}

" ...

If the message file defines 'msg=Delete

{0}

' then you normally use
h:outputFormat with a nested f:param to format the parameterised
message. However, then there is no obvious way to use the result in an
attribute value. Currently, you probably have to write your own JSTL
function, such as the following syntax a JSTL varargs function:

<h:commandLink value="#

{f:outputFormat('msg', name)}

" ...

2. Formatted message parameter:

Last updated <h:outputText value="#

{date}" converter="customDate"/>

If the message file defines 'msg=Last updated {0,date}' then there is no
obvious way to format the date using the custom JSF converter instead of
the standard date formatting. It also seems impossible to format the
date before passing it to h:outputFormat because the a nested f:param
takes its value from an attribute.

Again, you could work-around this with a JSTL converter function, e.g.

<h:outputFormat value="#{msg}">
<f:param value="#{f:convert('customDate', date)}"/>
</h:outputFormat>

Perhaps something like the following syntax makes sense:

<h:outputFormat value="#{msg}">
<f:param value="#{date}

" converter="customDate"/>
</h:outputFormat>

3. JSF component in message:

See the <h:commandLink ... >related items</h:commandLink>

This is similar to the 'formatted message parameter' case, but in this
case you need to be able to format a parameterised message by passing a
JSF component (the link) as a parameter. Again, h:outputFormat does
not support this.

Perhaps something like the following syntax makes sense:

<h:outputFormat value="#

{msg}

">
<f:param>
<h:commandLink ... >
<h:outputText value="#

{msg2}

"/>
</h:commandLink>
</f:param>
</h:outputFormat>

Environment

Operating System: All
Platform: All

Affected Versions

[2.0]

@glassfishrobot
Copy link
Author

Reported by peter_hilton

@glassfishrobot
Copy link
Author

peter_hilton said:
Changed target milestone to 2.0

@glassfishrobot
Copy link
Author

@edburns said:
Move to unscheduled target milestone

@glassfishrobot
Copy link
Author

@edburns said:
Prepare to delete "spec" subcomponent.

@glassfishrobot
Copy link
Author

mojavelinux said:
Target milestone should be 2.1

Ideally the category for this issue should be i18n, if it existed.

@glassfishrobot
Copy link
Author

@edburns said:
triage

@glassfishrobot
Copy link
Author

@edburns said:
rogerk

@glassfishrobot
Copy link
Author

rogerk said:
triage

1 similar comment
@glassfishrobot
Copy link
Author

rogerk said:
triage

@glassfishrobot
Copy link
Author

@arjantijms said:
As for point 3, the proposed syntax certainly seems to make sense as we independently came up with the exact same one. For those wanting to test its usefulness, it's implementable by users as follows:

Define a map as managed bean:

<managed-bean>
    <description>Request scoped buffer for general usage</description>
    <managed-bean-name>buffer</managed-bean-name>
    <managed-bean-class>java.util.HashMap</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

Define a custom Facelets tag that uses the Tomahawk library:

**param.xhtml**<ui:composition
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core"    
    xmlns:t="http://myfaces.apache.org/tomahawk"
>	
    <!-- Render content into a buffer -->
    <t:buffer into="#{buffer['_parameter']}">
        <ui:insert></ui:insert>
    </t:buffer>	

    <f:param value="#{buffer['_parameter']}" />	
</ui:composition>

Use on a Facelet as:

<h:outputFormat value="#{i18n['some.key']}" escape="false" >
    <my:param>
        <h:outputLink value="somelink.html">
            #{i18n['some.otherkey']}
        </h:outputLink>
    </my:param>				
</h:outputFormat>

@glassfishrobot
Copy link
Author

@edburns said:
<f:loadBundle> is not the recommended way to do L10N anyway. Use the in faces-config.

@glassfishrobot
Copy link
Author

Marked as won't fix on Friday, January 24th 2014, 12:57:07 pm

@glassfishrobot
Copy link
Author

@manfredriem said:
Closing resolved issue out

@glassfishrobot
Copy link
Author

This issue was imported from java.net JIRA JAVASERVERFACES_SPEC_PUBLIC-517

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant