Hi all,
How can we combine enumeration with internationalization in java?
here is an example that I worked on it but get confused
we have an enumeration Title as :
package internationalisation;
public enum Title {
Mr, Ms, Miss;
}
and the Employee entity:
package entities;
@Entity
public class Employee{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column(name="name", length = 30)
private String name;
@Enumerated(EnumType.ORDINAL)
@Column(name="title", columnDefinition = "char(1)")
private Title title;
// getters ans setters
}
in the JSF form the title flied will display the title values in a selectOneMenu tag depending on the langauge selected :
for example: for English : Mr, Ms, Miss and for French: Mr, Madame, Mlle form,
to do so I needed properties files
Title-US and
Title-FR witch contains the following:
# Title-FR file
Mr = Mr
Miss = Mlle
Ms = Madame
#Title-US file
Mr = Mr
Miss= Miss
Ms = Ms
how can I make the enumeration do this??
I tried this but get confused :
package localisation;
import java.util.ResourceBundle;
public enum Title {
Mr, Ms, Miss;
private static String language;
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
Title.language = language;
}
private static final ResourceBundle res = ResourceBundle.getBundle("Title-"+language+".properties");
public String toString() {
return res.getString(name());
}
}
thanks for help