Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BotAdapter updates for locale.
  • Loading branch information
LeeParrishMSFT committed Mar 23, 2021
commit 8c3cbc6e6a6fe887dbf2e772421ad78ba661fce7
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.microsoft.bot.schema.ResourceResponse;

import java.util.List;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import org.apache.commons.lang3.NotImplementedException;
Expand Down Expand Up @@ -196,6 +197,9 @@ protected CompletableFuture<Void> runPipeline(
// Call any registered Middleware Components looking for ReceiveActivity()
if (context.getActivity() != null) {
if (!StringUtils.isEmpty(context.getActivity().getLocale())) {

Locale.setDefault(Locale.forLanguageTag(context.getActivity().getLocale()));

context.setLocale(context.getActivity().getLocale());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ public void PassResourceResponsesThrough() {
);
}

@Test
public void GetLocaleFromActivity() {
Consumer<List<Activity>> validateResponse = (activities) -> {
// no need to do anything.
};
SimpleAdapter a = new SimpleAdapter(validateResponse);
TurnContextImpl c = new TurnContextImpl(a, new Activity(ActivityTypes.MESSAGE));

String activityId = UUID.randomUUID().toString();
Activity activity = TestMessage.Message();
activity.setId(activityId);
activity.setLocale("de-DE");
BotCallbackHandler callback = (turnContext) -> {
Assert.assertEquals("de-DE", turnContext.getActivity().getLocale());
return CompletableFuture.completedFuture(null);
};

a.processRequest(activity, callback).join();
}


@Test
public void ContinueConversation_DirectMsgAsync() {
boolean[] callbackInvoked = new boolean[] { false };
Expand Down