1

I am trying to show a welcoming message in a JSF page in different languages (English or Spanish) depending on the user's browser configuration.

These are the steps I follow:

1-In Netbeans I create a WAR project

2-In the folder Source Packages I create a package named locale, and inside that package, I create 2 files (messages.properties, messages_es.properties)

messages.properties

greeting = Welcome!

messages_es.properties

greeting = Bienvenido!

3-In the folder Web Pages I create the file index.html

<h:outputText value="#{msg['greeting']}" />

4-In faces-config.xml I write this code:

<locale-config>
            <default-locale>en</default-locale>
            <supported-locale>es</supported-locale>
        </locale-config>
        <resource-bundle>
            <base-name>locale.messages</base-name>
            <var>msg</var>
        </resource-bundle>

When I run the application in my browser always is shown the welcoming message in Spanish (BIenvenido!), also when I change the preference order (Preferences-Content-Language) to show the web page in English.

What am I doing wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
jose
  • 303
  • 4
  • 17
  • What's the value of `Accept-Language` request header sent by client? – BalusC May 30 '15 at 13:58
  • This are Firefox language settings: http://postimg.org/image/acii6kozd/ I dom't know if this answers your question. SHould I Install wireshark to see the Accept-Language value? – jose May 30 '15 at 14:07
  • You can just find it in browser's HTTP traffic monitor as available via F12 > Network. – BalusC May 30 '15 at 14:07
  • Accept-Language: en,es;q=0.8,es-ES;q=0.6,en-US;q=0.4,de;q=0.2 – jose May 30 '15 at 14:22
  • @BalusC I finally managed to find the error. I changed the messages.properties file name to messages_en.properties and it works well. Thank you – jose May 30 '15 at 14:35

1 Answers1

2

I finally managed to find the error. I changed the messages.properties file name to messages_en.properties and it works well.

jose
  • 303
  • 4
  • 17