Message bundles in JSF

internationalization, jsf

Solution

I suggest you begin with the single File approach, one per language. If it grows in a level that you simply can't manage anymore, thousands of lines, than you might split it.

Then you can internationalize your pages using a template that will have:

<f:view locale="#{userBean.userLocale}">

and you can enable a select component to hold the available languages for the users to switch:

FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);

and in faces-config.xml:

    <application>        
        <locale-config>            
            <default-locale>pt-br</default-locale>
            <supported-locale>en</supported-locale>            
        </locale-config>

        <resource-bundle>
            <base-name>com.myapp.blah.ApplicationResources</base-name>
            <var>msg</var>
        </resource-bundle>
...

then you shall have one file per language:

ApplicationResources.properties ApplicationResources_en.properties ApplicationResources_pt_BR.properties

Problem

I am using JSF and I want to use message bundles so I added the XML configuration below. Now I wonder if someone could write some experiences they had when using them. Is it best practice to have one big properties file that contain all translation on the page, if so how do you name your keys. If not, then I guess you have multiple resource files, how do you structure them - what part of the page do they provide messages for? - and any naming practices? I know this may be subjective but it could be valuable insights for me anyway. ``` <application> <resource-bundle> <base-name>com.myapp.blah</base-name> <var>msgs</var> </resource-bundle> </application> ```

Original source

Related problems