open-horizon / exchange-api

Horizon Exchange REST API Server
Apache License 2.0
11 stars 30 forks source link

Exchange support specifying language on each API call #469

Open bmpotter opened 3 years ago

bmpotter commented 3 years ago

Currently environment variable HZN_EXCHANGE_LANG or LANG need to be set when starting the exchange server in order to get messages in a different language. It would be more convenient/flexible if the client could specify what language it wants that 1 response in.

mabdh commented 3 years ago

hi @bmpotter , I am interested to pick this issue.

can you assign it to me please?

bmpotter commented 3 years ago

@mabdh sure

bmpotter commented 3 years ago

@mabdh You asked what i meant by the 2nd bullet in the description. The method https://github.com/open-horizon/exchange-api/blob/1ea5761cfeb9f6ff85d0e74726aed6e9532c1e6d/src/main/scala/com/horizon/exchangeapi/ApiUtils.scala#L181 needs to be able to know the languages that were requested in the Accept-Language header. But ExchMsg.translate() doesn't have access to the Akka client request object, and it is called from way too many places to add a regular parameter to it. So i'm hoping each class/trait that calls it can add an implicit variable for the request.

Once that method has the request available to it, you can see an example of pulling a header out of the Akka request at https://github.com/open-horizon/exchange-api/blob/1ea5761cfeb9f6ff85d0e74726aed6e9532c1e6d/src/main/scala/com/horizon/exchangeapi/AuthenticationSupport.scala#L168 .

BTW, for future discussion, it might be easier to chat on the LF Edge open-horizon-mgmt-hub channel.

mabdh commented 3 years ago

Noted @bmpotter

It is actually quite clear after seeing through the code. I just figured out Akka has a MiscDirective called selectPreferredLanguage that might be useful for this use case.

I used to code in Go and clojure and was not really familiar with scala but I think this is the good time to explore more and get used to it.

Sure let me raise further questions om the slack channel.

MOLOCH-dev commented 2 years ago

Hello, I would like to contribute to this issue. I would also appreciate any tips for beggining to contribute, thank you!