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

Cross-Train generates a file with wrong culture #1295

Closed
MatteoMeil opened this issue Sep 16, 2021 · 4 comments · Fixed by #1300
Closed

Cross-Train generates a file with wrong culture #1295

MatteoMeil opened this issue Sep 16, 2021 · 4 comments · Fixed by #1300
Assignees
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-reported Issue is created by anyone that is not a collaborator in the repository.

Comments

@MatteoMeil
Copy link

Versions

What CLI version are you using: 4.14.1
What Nodejs version are you using: 14.17.1
What command-line interpreters are you using: CMD (Windows' command prompt)
What OS are you using: Win10 x64

Describe the bug

If a file is created without app information in the header part (i.e.: @app.version etc.), culture specified via filename, e.g.: MyBot.it-it.lu is not taken into account. This causes a wrong check for prebuilt entities availability.

This closely relates to #1292. In fact, that issue must be addressed before this one to allow the culture information to pass along methods' calls.

Possible solution in first comment.

To Reproduce

BF Composer Way

  1. Generate a new Project
  2. Change Localization as you wish. It must not be en-us
  3. Define some triggers and run the build
  4. Check for .lu files generated in path/to/your/bot/generated/interruption. In header section you will find for every .lu file
    > !# @app.culture = en-us
    

BF CLI way

  1. Create a new file without culture information in header
  2. Insert culture in file name, e.g.: MyBot.it-it.lu
  3. In the same folder run bf luis:cross-train passing arguments as per docs
  4. Check generated files. In header section you will find for every .lu file
    > !# @app.culture = en-us
    

Expected behavior

It should generate a .lu file with correct culture information, provided it's not specified in file header but it is in filename.

Screenshots

Not applicable

Additional context

This issue affects also BotFramework Composer which makes use of cross train to generate intermediate .lu files

[bug]

@MatteoMeil MatteoMeil added bug Indicates an unexpected problem or an unintended behavior. needs-triage The issue has just been created and it has not been reviewed by the team. labels Sep 16, 2021
@MatteoMeil
Copy link
Author

One possible solution I found is to check here for culture information in file name and possibly update this.language:

const fileHelpers = require('./../../utils/filehelper');

// ...

class Lu {
  constructor(content, options = new luOptions){
    // ...
    
    if (this.language !== '') {
      this.name = this.id + '.' + this.language + '.lu'
    } else {
      this.name = this.id + '.lu'
      // Check if culture is specified in name
      const fileCulture = fileHelpers.getLuisCultureFromPath(this.name);

      if (fileCulture) {
        // If so, update language property
        this.language = fileCulture;
      }
    }
  }
}

// ...

This permits to have luOb.language filled in this line and updating this method call, as I suggested in #1292, permits the flow of culture information along the chain.
Moreover, this method also needs to be updated to check if culture information is present in header and, if not, set it accordingly:

const parseAndHandleModelInfoSection = function (parsedContent, luResource, log, config, locale = '') {
  // ...

  let cultureSet = false;
  
  if (modelInfos && modelInfos.length > 0) {
    // ...

    for (const modelInfo of modelInfos) {
      //...

      if (kvPair.length === 4) {
        // ...

        if (kvPair[1].toLowerCase() === 'app') {
          if (kvPair[2].toLowerCase().startsWith('settings')) {
            // ...
          } else {
            cultureSet = kvPair[2].toLowerCase() === 'culture';
            parsedContent.LUISJsonStructure[kvPair[2]] = kvPair[3];
          }
        }

        // ...

      }

      // ...
    }

    // ...
  }

  if (!cultureSet && locale) {
    parsedContent.LUISJsonStructure.culture = locale;
  }
}

Eventually, call of this method here needs to be updated to:

let enableMergeIntents = parseAndHandleModelInfoSection(parsedContent, luResource, log, config, locale);

@dmvtech dmvtech added Bot Services Required for internal Azure reporting. Do not delete. Do not change color. customer-reported Issue is created by anyone that is not a collaborator in the repository. labels Sep 16, 2021
@srinaath srinaath removed the needs-triage The issue has just been created and it has not been reviewed by the team. label Sep 17, 2021
@srinaath
Copy link

@boydc2014 Could you have a look at this ticket when you get a moment.

@boydc2014
Copy link
Contributor

@boydc2014 Could you have a look at this ticket when you get a moment.

Sure looking at it.

@boydc2014
Copy link
Contributor

@cosmicshuai have a PR to fix this linked above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bot Services Required for internal Azure reporting. Do not delete. Do not change color. bug Indicates an unexpected problem or an unintended behavior. customer-reported Issue is created by anyone that is not a collaborator in the repository.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants