문제

I have to load the properties files based on the locale and i have below code in my servlet.

ResourceBundle contactBundle = ResourceBundle.getBundle("/popproperties/impprops", request.getLocale());

also i created props file as below inside popproperties folder.

impprops_en_US.properties

//some key value pairs here

Above code works fine without any issues. My question is i have only one porperties file as impprops_en_US.properties. If user changes browser settings from US to some other locale then there is no other corresponding locale's properties file. In such a case still i have to load impprops_en_US.properties file. How can i do that? do i need to create one more properties file as impprops.properties ?

Thanks!

도움이 되었습니까?

해결책

It depends on your code like if you are getting null/default on selecting a default locale then accordingly you can make a check and load the desired locale. For ex ,In my case :

   String cc=req.getParameter("country");
   String ln=req.getParameter("language");
   Locale l=null;
   if(cc==null)
     l=new Locale("en","US");
   else
     l=new Locale(ln,cc);

   ResourceBundle rb=ResourceBundle.getBundle("ApplicationResources",l);
   req.setAttribute("resource", rb);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top