cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CAP - Add Header / Language Parameters at Runtime

tobiasfue
Explorer

Hello,

I know that I can attach arbitrary headers dynamically/at runtime in the Cloud SDK.

Is this also possible in the Java CAP environment?

I consume 3-4 standard APIs that provide a translation if I include a sap-language header. However, it can only be decided at runtime which language is desired. I can't find any option in the CQN API.

Does anyone know a possibility? Thanks!

View Entire Topic
marcbecker
Contributor

CAP Java stores the current Locale in the RequestContext, see also https://pages.github.tools.sap/cap/docs/java/request-contexts

The Locale from the RequestContext is automatically added as sap-language query parameter or Accept-Language header when using the RemoteServices feature. Do you really need a sap-language header?

You can control and overwrite the Locale in the RequestContext, for example:

runtime.requestContext().modifyParameters(p -> p.setLocale(someLocale)).run(requestContext -> {
  // execute CQN query in this scope
});
tobiasfue
Explorer

Hi Marc,

thanks for this hint. I will try it.

The API translates the texts only if the header is set. URL parameter is ignored.

radu_simen
Explorer
0 Kudos

what about when calling and external action/function via an EventContext.

Does it work setting the locale via action/function EventContext ?

eventContext.getParameterInfo.copy().setLocale(...)
service.emit(eventContext)