Search code examples
jsf-2internationalizationresourcebundle

Overriding JSF's default I18N handling


Like the asker of the question here

Variable substitution JSF Resource Bundle property file

I'm slightly aghast at the inability to reference the value of other property keys in the message bundle.

Although I see how easy to write my own rubbish handler[0] that can do what I want in a custom component, that would leave expressions in templates calling the message bundle still using the default JSF implementation.

Is it possible to override the default JSF handling of the message bundle?

[0] Or better, to use code referenced in one of the answers to the above question https://code.google.com/p/reflectiveresourcebundle/


Solution

  • You can provide the fully qualified name of a concrete ResourceBundle implementation as "base name" instead of alone the path and filename of the properties files.

    E.g.

    public class YourCustomResourceBundle extends ResourceBundle {
        // ...
    }
    

    which can be registered as follows

    <application>
        <resource-bundle>
            <base-name>com.example.YourCustomResourceBundle</base-name>
            <var>text</var>
        </resource-bundle>
    </application>
    

    or declared on a per-view/template basis as follows

    <f:loadBundle baseName="com.example.YourCustomResourceBundle" var="text" />
    

    Here are several related questions/answers which contain some concrete code which you could use as a kickoff example: