You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Patrick Kolodziejczyk <pa...@viseo.com> on 2014/06/11 17:16:16 UTC

I18N with Accept-Language header

Hi,

I am looking to add internationalization on my webservice that work on tomcat.
In one old documentation of Tomcat, it's speak about the Header parameter "Accept-Language" that is read by StaticInterceptor and set the Locale.
Source : http://tomcat.apache.org/tomcat-3.3-doc/serverxml.html

It's just what I need to use the right ResourceBundle with out adding explicitly a parameter in all my services.
But I don't find others documentation about it... On newer version (I use tomcat 6) or on how configure it.


I did some test for see if the parameter is send (and it's)
    @POST
    @Path("/create/")
    public WSBooleanResponse create(EnvoyerEmailActivationCompteProxy tiers, @HeaderParam("Accept-Language") String language) {
        ServiceResponse response = createDefaultServiceResponse();

        System.out.println(language);

        if(language != null){
            LocaleEditor le =new LocaleEditor();
            le.setAsText(language);
            Locale.setDefault((Locale) le.getValue());
        }

But I don't have StaticInterceptor declared in my server.xml and I don't know where I need to put it in the structure.

If someone have any experience on it, or any documentation. It's will help me a lot.

Truly,



Patrick Kolodziejczyk
Ingénieur Conception et Développement
BU technologies - Groupe Viseo
190, rue Garibaldi - 69003 LYON
Tél.  +33 (0)4 72 33 78 30
http://www.viseo.com<http://objetdirect.com/>

RE: I18N with Accept-Language header

Posted by Patrick Kolodziejczyk <pa...@viseo.com>.
Don't really understand how work that method.
Cause I did a test with this code :

	@Context private HttpServletRequest servletRequest;
	@POST
	@Path("/create/")
	public WSBooleanResponse create(EnvoyerEmailActivationCompteProxy tiers, @HeaderParam("Accept-Language") String language) {
		ServiceResponse response = createDefaultServiceResponse();
		System.out.println("Via servlet =>"+servletRequest.getLocale());
		System.out.println(language);

It's should give me :
    Via servlet =>en_GR
    en_GR

But I got :
    Via servlet =>fr_FR
    en_GR

(My Java is fr_FR by default)

Did I miss spell "Accept-Language" ? Or It's should be more that just "Accept-Language" : "en_GR" in the header ? 

Patrick Kolodziejczyk
Ingénieur Conception et Développement
BU technologies – Groupe Viseo
190, rue Garibaldi - 69003 LYON
Tél.  +33 (0)4 72 33 78 30
http://www.viseo.com

________________________________________
De : Konstantin Kolinko <kn...@gmail.com>
Envoyé : mercredi 11 juin 2014 17:55
À : Tomcat Users List
Objet : Re: I18N with Accept-Language header

2014-06-11 19:16 GMT+04:00 Patrick Kolodziejczyk
<pa...@viseo.com>:
> Hi,
>
> I am looking to add internationalization on my webservice that work on tomcat.
> In one old documentation of Tomcat, it's speak about the Header parameter "Accept-Language" that is read by StaticInterceptor and set the Locale.
> Source : http://tomcat.apache.org/tomcat-3.3-doc/serverxml.html
>
> It's just what I need to use the right ResourceBundle with out adding explicitly a parameter in all my services.
> But I don't find others documentation about it... On newer version (I use tomcat 6) or on how configure it.
>
>
> I did some test for see if the parameter is send (and it's)
>     @POST
>     @Path("/create/")
>     public WSBooleanResponse create(EnvoyerEmailActivationCompteProxy tiers, @HeaderParam("Accept-Language") String language) {
>         ServiceResponse response = createDefaultServiceResponse();
>
>         System.out.println(language);
>
>         if(language != null){
>             LocaleEditor le =new LocaleEditor();
>             le.setAsText(language);
>             Locale.setDefault((Locale) le.getValue());
>         }
>
> But I don't have StaticInterceptor declared in my server.xml and I don't know where I need to put it in the structure.
>
> If someone have any experience on it, or any documentation. It's will help me a lot.
>

In Servlet API the locales specified in "Accept-Language" header are
available via  javax.servlet.ServletRequest.getLocales()  method.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: I18N with Accept-Language header

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-06-11 19:16 GMT+04:00 Patrick Kolodziejczyk
<pa...@viseo.com>:
> Hi,
>
> I am looking to add internationalization on my webservice that work on tomcat.
> In one old documentation of Tomcat, it's speak about the Header parameter "Accept-Language" that is read by StaticInterceptor and set the Locale.
> Source : http://tomcat.apache.org/tomcat-3.3-doc/serverxml.html
>
> It's just what I need to use the right ResourceBundle with out adding explicitly a parameter in all my services.
> But I don't find others documentation about it... On newer version (I use tomcat 6) or on how configure it.
>
>
> I did some test for see if the parameter is send (and it's)
>     @POST
>     @Path("/create/")
>     public WSBooleanResponse create(EnvoyerEmailActivationCompteProxy tiers, @HeaderParam("Accept-Language") String language) {
>         ServiceResponse response = createDefaultServiceResponse();
>
>         System.out.println(language);
>
>         if(language != null){
>             LocaleEditor le =new LocaleEditor();
>             le.setAsText(language);
>             Locale.setDefault((Locale) le.getValue());
>         }
>
> But I don't have StaticInterceptor declared in my server.xml and I don't know where I need to put it in the structure.
>
> If someone have any experience on it, or any documentation. It's will help me a lot.
>

In Servlet API the locales specified in "Accept-Language" header are
available via  javax.servlet.ServletRequest.getLocales()  method.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org