views:

34

answers:

1

Hello,

This is my messages_en_US.properties file in WEB-INF/classes folder :-

Login=Login

And then i created messages_fr_FR.properties :-

Login=frenchLogin

Then in my JSF page i wrote this :-

 <f:loadBundle basename="messages" var="msg"/>

<h:commandButton id="btnLogin" value="#{msg.Login}" actionListener="#{IndexBean.doLogin}"/>

I can correctly see the Login text by default. But when i go in firefox and change my default language to fr-fr, my text still remains the same i.e i can't see frenchLogin.

I don't have anything in my faces-config.xml

What am i doing wrong? Thanks in advance :)

+3  A: 

You have to have this in the faces-config.xml

    <application>
        <message-bundle>com.mydomain.resources.Messages</message-bundle>
        <locale-config>
            <default-locale>fr_FR</default-locale>
            <supported-locale>en_EN</supported-locale>
        </locale-config>
    </application>

You need a Messages.properties which will be the default one.

in your jsf page:

<f:loadBundle basename="com.mydomain.resources.Messages" var="msg" />

The messages file has to be in src/main/java/ and then in a package. Mine is /src/main/java/com/mydomain/resources

Also be careful with the capital letters.

pakore
Thanks :). I got CONFIGURATION FAILED exception at first but when i removed `<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>` it works fine. Thanks again.
Ankit Rathod
that's because you are not using facelets I guess. Sorry about that, I forgot to remove that line.
pakore
Also can you suggest any easy way where i can get equivalent text of all english words in french?
Ankit Rathod
I am using facelets only.
Ankit Rathod
@Nitesh: http://translate.google.com ?
BalusC
Thanks BalusC, exactly what i needed :)
Ankit Rathod
I'd recommend you not doing that, because the translation is sometimes related to its context. You need to translate the keys manually, because you are the only one who knows where are they going to appear.
pakore
@Nitesh then I don't know why you got that error :). If it works, I'm happy then :P
pakore
You are right pakore. But my requirement is simple and not that complex. For a entire complex paragraph of text, i use Google Ajax Translation. But for simple button text like Login, Logout etc i am using these properties file.
Ankit Rathod
Google Translate is indeed fine for simple words, but for complete paragraphs and so on, better hire a real humanoid translator.
BalusC