cancel
Showing results for 
Search instead for 
Did you mean: 

How can I change the language being used for a gateway session

Sigurdur
Participant

Hi

I have a gateway service that needs to service users with different languages, and the best way I have found is to implement a method to fetch the language from request header.

But the downside is that I have to include this method call in every enitity implemented and therefore this is often called multiple times per request.

Is there a way to set the language as a global attribute in the gateway object modea and prehap redifine some base class method to set the language automatically in every request ?

  METHOD get_language.
    DATA : lo_facade         TYPE REF TO /iwbep/if_mgw_dp_int_facade,
           lt_client_headers TYPE tihttpnvp,
           lw_client_headers LIKE LINE OF lt_client_headers.
    TRY.
        lo_facade ?= /iwbep/if_mgw_conv_srv_runtime~get_dp_facade( ).
        lt_client_headers = lo_facade->get_request_header( ).
      CATCH /iwbep/cx_mgw_tech_exception.
    ENDTRY.
    LOOP AT lt_client_headers INTO lw_client_headers WHERE name = 'accept-language'.
      IF lw_client_headers-value CS 'en'.  
        ov_language = 'E'.  
      ELSEIF lw_client_headers-value CS 'pl'.
        ov_language = 'L'.  
      ENDIF.
    ENDLOOP.
       SET LANGUAGE ov_language.
       sy-langu = ov_language.
  ENDMETHOD.

Accepted Solutions (0)

Answers (2)

Answers (2)

enric101
Active Contributor

The frontend determine automatically the lenguaje from browser configuration, if you need to change this default lenguage you can use a parameter in URL or using sapui5 library:

With code:

sap.ui.getCore().getConfiguration().setLanguage("de");

With parameters:

sap-language=DE

And in order to use this language in the gateway is only necessary indicates this language at logon

Regards

Sigurdur
Participant
0 Kudos

I'm not using fiori and sapui5 as frontend

enric101
Active Contributor
Sigurdur
Participant
0 Kudos

Hi Enric

This is not what I'm looking for. I want to let the front end switch to the language the users browser is using. And how to best accomplish that within the Gateway class hirachy