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

[Port] Localization: fix bugs around inconsistent locale + first step to centralize locale resolution #3340

Merged
merged 11 commits into from
Mar 10, 2021

Conversation

cosmicshuai
Copy link
Contributor

@cosmicshuai cosmicshuai commented Feb 24, 2021

closes: #3311 #3188

Also includes changes in microsoft/botbuilder-dotnet#5019.

@cosmicshuai cosmicshuai requested review from a team as code owners February 24, 2021 10:08
@@ -123,6 +123,8 @@ describe('LGLanguageGenerator', function() {

this.beforeAll(async function() {
const multiLanguageResources = await LanguageResourceLoader.groupByLocale(resourceExplorer);

//Should have a setup for the threadLocale here.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

const locale = this.context.activity?.locale;
if (locale !== undefined) {
Copy link
Contributor Author

@cosmicshuai cosmicshuai Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in .NET, here is

if (!string.IsNullOrEmpty(locale)). 

if we keep the same here, it will break some tests in LGGenerator.test.js
Do we have a workaround to change the enviroment locale in node?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the environment locale set in .NET? Since we don't have threads or any other natural isolation, setting values on a context parameter (i.e. this.context) is likely the cleanest way to achieve the same functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In .NET, it is

Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ar");

Or maybe we can slightly modify the tests in javascript since it is hard to modify the environment locale.

Copy link
Contributor

@joshgummersall joshgummersall Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm wondering if this is something we can really do in Javascript. There is no notion of threads or domains (well, they're deprecated anyways) to support collecting context or culture. We have functions and arguments, and we already have a context argument that gets passed around. Is that context parameter not sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the current workaround is OK. An empty string in locale, both LG and expression will fallback to the correct locale resolution.

@coveralls
Copy link

coveralls commented Feb 24, 2021

Pull Request Test Coverage Report for Build 636945958

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 10 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.03%) to 84.807%

Files with Coverage Reduction New Missed Lines %
libraries/botbuilder-dialogs-adaptive/src/input/confirmInput.ts 1 86.52%
libraries/botbuilder-dialogs-adaptive/src/input/dateTimeInput.ts 1 77.5%
libraries/botbuilder-lg/src/templateExtensions.ts 1 84.48%
libraries/botbuilder-core/src/turnContext.ts 2 97.6%
libraries/botbuilder-dialogs/src/dialogContext.ts 2 95.61%
libraries/botbuilder-dialogs-adaptive/src/generators/multiLanguageGeneratorBase.ts 3 88.0%
Totals Coverage Status
Change from base Build 636944669: -0.03%
Covered Lines: 18664
Relevant Lines: 20952

💛 - Coveralls

}

const locale = this.context.activity?.locale;
if (locale !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the environment locale set in .NET? Since we don't have threads or any other natural isolation, setting values on a context parameter (i.e. this.context) is likely the cleanest way to achieve the same functionality.

@@ -12,7 +12,7 @@ import { DialogContext } from '../../dialogContext';
/**
* @private
*/
const TURN_STATE = Symbol('turn');
const TURN_STATE = 'turn';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevengum, the only issue I could see here is conflicting with code that used the 'turn' state key. Is that me being too paranoid about backward compatibility?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have some built in turn states with string keys, is there a way to notify our users that these keys are reserved keys?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of - @stevengum any thoughts?

@cosmicshuai cosmicshuai merged commit c91bf14 into main Mar 10, 2021
@cosmicshuai cosmicshuai deleted the shuwan/localization-bugs branch March 10, 2021 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

port: Localization: fix bugs around inconsistent locale + first step to centralize locale resolution (#5218)
4 participants