tags:

views:

97

answers:

2

I am using an enumeration class in my GWT client's code to define a set of types.

public enum MyType {

    FIRST_TYPE("first"), SECOND_TYPE("second"), THIRD_TYPE("third");

    private String title;

    private MyType(String title) {
        this.title = title;
    }

    public String getTitle() {
        return this.title;
    }

}

How is it possible to localize the enum values to translate them into different languages? The title field is not that important and could be dropped if this helps to solve the problem.

I know the ResourceBundle approach from Java, but that is not working in GWT's client code.

+1  A: 

Maybe this will help you, since it seems to be the gwt way Internationalization

InsertNickHere
Thanks for the hint. I already use `Constants` and `Messages` interfaces but never came in touch with `ConstantsWithLookup` interface.
thommyslaw
+2  A: 

I managed to solve the problem by using GWT's ConstantsWithLookup interface. Here is the solution:

MyType.java

public enum MyType {

    FIRST_TYPE, SECOND_TYPE, THIRD_TYPE;

    private final MyConstantsWithLookup constants = GWT.create(MyConstantsWithLookup.class)

    public String getTitle() {
        return this.constants.getString(this.name());
    }
}

MyConstantsWithLookup.java

public interface CommonConstantsWithLookup extends ConstantsWithLookup {

    String FIRST_TYPE();

    String SECOND_TYPE();

    String THIRD_TYPE();
}

MyConstantsWithLookup.properties

FIRST_TYPE = first
SECOND_TYPE = second
THIRD_TYPE = third
thommyslaw