Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

enumeration and internationalization

REDO LOGMar 9 2013 — edited Mar 9 2013
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 6 2013
Added on Mar 9 2013
9 comments
744 views