Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button Text / User Input Choices in Prompt Translation/Localization not possible #9342

Open
saskialorraine opened this issue Aug 10, 2022 · 10 comments
Labels
Backlog Backlog items - not in current milestone Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete. feature-request A request for new functionality or an enhancement to an existing one.

Comments

@saskialorraine
Copy link

saskialorraine commented Aug 10, 2022

Hello there,

Currently the responses/texts are being stored in the bots lg files, which is fine and works great with translation.
Unfortunately, the texts which the buttons contain are stored in the dialog files.

For translation, the LG Files are being duplicated and named accordingly (e.g. de-de, en-us).
BUT for the dialog files that is not possible.
There is only one dialog file.

My question: is there a way to either have the button/input choices text in the lg files and then referring to the dialog file with e.g. a template, or is there another scalable and practical way to translate the button texts?

Greetings and thanks in advance.

@saskialorraine saskialorraine added Needs-triage A new issue that require triage Type: Bug Something isn't working labels Aug 10, 2022
@stevkan stevkan added customer-reported Required for internal Azure reporting. Do not delete. Bot Services Required for internal Azure reporting. Do not delete. Do not change color. labels Aug 10, 2022
@stevkan stevkan self-assigned this Aug 10, 2022
@stevkan
Copy link
Contributor

stevkan commented Aug 10, 2022

@saskialorraine - Taking a look at this to see if there are any workable solutions. I'll reach out to you when I know more.

@stevkan stevkan removed the Needs-triage A new issue that require triage label Aug 10, 2022
@johnkm516
Copy link

johnkm516 commented Aug 11, 2022

@saskialorraine
You can create template functions in each locale lg file like this :

In en-us.lg file :

# SendActivity_ChooseNoIntent()
- Sure, no worries.

In ko-kr.lg file :

# SendActivity_ChooseNoIntent()
- 네, 알겠습니다.

Then create a response with text that refers to the template you created :

image

[Activity
    Text = ${SendActivity_ChooseNoIntent()}
]

The same goes for attachments. Instead of text in the template function you would instead write json for an adaptive card like this (in your case your card would have a button rather than what I have below), and like above with text, you would change the text of your buttons depending on your locale :


# SendActivity_ChooseIntentPrompt_attachment_card(candidates)
-```
{
      "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
      "version": "1.0",
      "type": "AdaptiveCard",
      "speak": "",
      "body": [
          {
              "type": "TextBlock",
              "text": "${SendActivity_ChooseIntentPrompt_attachment_whichOneDidYouMean()}",
              "weight": "Bolder"
          },
          {
              "type": "TextBlock",
              "text": "${SendActivity_ChooseIntentPrompt_attachment_pickOne()}",
              "separator": "true"
          },
          {
              "type": "Input.ChoiceSet",
              "placeholder": "Placeholder text",
              "id": "userChosenIntent",
              "choices": [
                           ${SendActivity_ChooseIntentPrompt_attachment_generateChoices()},
                           {
                               "title": "None of the above",
                               "value": "none"
                           }
             ],
             "style": "expanded",
             "value": "luis"
         },
         {
             "type": "ActionSet",
             "actions": [
                {
                     "type": "Action.Submit",
                     "title": "Submit",
                     "data": {
                   "intent": "chooseIntentCardResponse"
                }
         }
       ]
     }
    ]
}
```<-- Note the json is surrounded by ```

@saskialorraine
Copy link
Author

@stevkan Thanks, that would be great!

@johnkm516 Thanks for your answer!

Did I understand that correctly though, that your solution would be to not use the prompts from BFC itself but exchange all of my questions with Adaptive Cards and read out those inputs?

That might be a solution indeed... but absolutely not a handy nor scalable one.

@johnkm516
Copy link

@saskialorraine

I am not sure what you mean by not scalable.
Templating using LG files allows you to customize the card (and therefore whatever prompts you want) in any way you'd like, and comes with pre-built functions that allows you to add loops and conditional statements. This means you can create your own version of a prompt that dynamically populates buttons with your own custom text. You could pass in an array of objects that look something like :

{
	"text" : "Click Me",
	"value" : "Value that will pass when clicked",
	"intent" : "Intent to pass when clicked"
},
...

then in your LG template, use a foreach loop and join the templates together with a comma delimiter.
For example :

# CalendarScheduleCard(data)
- ```
{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Container",
            "spacing": "None",
            "separator": true,
            "items": [
                ${join(foreach(data.dayRows, DateRow, DayRow(DateRow, data.currentMonth)), ',')}
            ]
        }
    ]
}
```
# DayRow(DateRow, currentMonth) 
- ```
{
    "type": "ColumnSet",
    "columns": [
        ${join(foreach(DateRow.entries, day, DayCell(day, currentMonth)), ',')}
    ],
    "style": "default",
    "spacing": "None"
}
```

In your case you would create a template that has JSON for a button, and use the foreach loop and join to dynamically populate the buttons depending on how many buttons you want.

Templating is far more flexible and scalable than the base prompts on BFC. You would create a template such as the example above once, and then pass in data that dynamically populates your card. This includes all the capabilities of adaptive cards, such as video media, images, etc. You can see all the pre-built functions that you can call in LG templates here :

https://docs.microsoft.com/en-us/azure/bot-service/adaptive-expressions/adaptive-expressions-prebuilt-functions?view=azure-bot-service-4.0

@saskialorraine
Copy link
Author

hello @johnkm516 thanks a lot for your detailed answers! It is very much appreciated!

I do see the advantages of the templating and adaptive cards, but the main issue is that we've already built a huge Bot Project with the BFC prompts and it would just mean a lot of work to replace those..

And in my opinion it is just a huge flaw if not a sort of bug that the buttons can just not easily be placed in the lg files for an easy translation or a different solution for Button translation

@johnkm516
Copy link

johnkm516 commented Aug 17, 2022

@saskialorraine
I looked over the source code for botbuilder-dotnet. You can look over Microsoft.Bot.Builder.Dialogs.Adaptive.Input.ChoiceInput.cs and other relevant files for reference.

I think the BFC prompts are the way they are currently because it was created before multi-locale support was even a thing. Furthermore BFC prompts use a custom choice recognizer to detect user responses on top of having the input buttons, it's not just a simple card dialog. This has put the developers in a precarious position because the design for locale support was meant to be done via the addition of LG files for each different locale, yet legacy actions such as prompts hardcode text in dialog files rather than generating an LG template like it's automatically done in Send Response. For a better understanding of how the locale support works, I suggest you look over Microsoft.Bot.Builder.Dialogs.Adaptive.Actions.SendActivity.cs, which now serves as the base for basically every bot generated response for multi-lingual bots as multi-lingual bots reference LG files for templating different responses per locale.

Here's the thing : even if BFC prompts are modified for multi-lingual support, it's going to reference LG files. That's the design direction of multi-lingual support. That means all the BFC prompts that's currently hardcoded in dialog files that you have currently has to be migrated over to LG files anyways. It's also difficult for MS to update BFC prompts because like you, many older chatbots use it and updating BFC prompts might break older chatbots. It's kind of a rock and a hard place type of situation IMO. MS might update BFC prompts and simultaneously change Composer or release a script to parse the dialog files and automatically update BFC prompts into the new updated prompt and migrate the prompts to LG files, but I'm not sure if this would be a priority or be released in due time. It would be faster if you coded your own parser to do the migration for you. Since dialog files are in JSON form it shouldn't be too difficult to code a program that finds and replaces ChoiceInput activities with SendActivity and append the appropriate LG files with the input in the dialog file.

Edit : To add, while I originally thought BFC prompts didn't currently support multi-lingual bots properly, you can simply reference the LG template in the dialog file instead. I was confused because currently BFC throws a warning when templating. But I found that this was a bug and there is currently a pull request that fixes it :

#9321

@saskialorraine
Copy link
Author

Hello together.

@johnkm516 Again: Thanks for your answer, very interesting and insightful.

We kinda figured it out/found a solution that we will probably use.
So we are now indeed using the templates placing them in the LG Files and implementing the template tags in the button field. Like so:

DE:
image
EN:
image
Code/LG Files:
image

BUT still it would just be very much appreciated and frankly easier and less time consuming if the Button texts would automatically appear as templates in the LG files instead of appearing in the dialog file.

@stevkan stevkan added customer-replied-to Required for internal reporting. Do not delete. feature-request A request for new functionality or an enhancement to an existing one. and removed Type: Bug Something isn't working labels Aug 18, 2022
@stevkan
Copy link
Contributor

stevkan commented Aug 18, 2022

@johnkm516 - Thank you for your insight and help on this issue. Your thoughts are on point and much appreciated!

@saskialorraine - I'm glad you were able to find a workable solution. I marked this as a feature request for future consideration. Of course, there is no ETA at this point on when this might be addressed.

@tdurnford tdurnford added the Backlog Backlog items - not in current milestone label Aug 18, 2022
@alitilitex
Copy link

@saskialorraine How did you get it to work? No matter how I write template variables into the choices array, they get printed as strings...

@saskialorraine
Copy link
Author

@alitilitex Could you provide a few screenshots? :) I worked with Composer quite a long time ago, so I would need some more information.

My first guess would be that you maybe didn't use a "=" before writing the variables in the choices. But if you create the template names according to my screenshot it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backlog Backlog items - not in current milestone Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-replied-to Required for internal reporting. Do not delete. customer-reported Required for internal Azure reporting. Do not delete. feature-request A request for new functionality or an enhancement to an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants