Skip to content

[PORT] Locale awareness in Adaptive-Expressions  #2652

@tomlm

Description

@tomlm

Port this change from botbuilder-dotnet/master branch:
microsoft/botbuilder-dotnet#4276

This PR contains the work in #4025. Since some force-pushed commits in previous PR introduced too many stuffs in the timeline, I created this new PR and closed that one.
@tomlm @chrimc62 @cleemullins @boydc2014 @Danieladu

  1. Locale is obtained from 'turn.activity.locale' when an incoming activity is recieved and the locale info will be set to 'turn.locale' in memory. Also user can use TurnContext.Locale to get and set locale.

  2. After a locale is set in TurnContext. It will be passed to EvaluationOptions in TemplateEngineLanguageGenerator. Then Options in Adaptive-Expressions will be updated.

  3. In locale related pre-built functions, the priority of locale follows: locale in APIs > locale from TurnContext > Thread.CurrentThread.CurrentCulture

Functions support locale paramter:
string(Object input, string locale?)
formatNumber(number input, integer precision, string locale?)
addToTime(string timestamp, integer interval, string unit, string format?, string locale?)
startOfDay(string timestamp, string format?, string locale?)
startOfHour(string timestamp, string format?, string locale?)
startOfMonth(string timestamp, string format?, string locale?)
convertToUTC(string timestamp, string timezone, string format?, string locale?)
convertFromUTC(string timestamp, string timezone, string format?, string locale?)
utcNow(string format?, string locale?)
getPastTime(integer interval, string unit, string format?, string locale?)
getFutureTime(integer interval, string unit, string format?, string locale?)
subtractFromTime(string timestamp, integer interval, string unit, string format?, string locale?)
formatEpoch(long epoch, string format?, string locale?)
formatTicks(long tictks, string format?, string locale?)
formatDateTime(string timestamp, string format?, string locale?)
addDays(string timestamp, int interval, string format?, string locale?)
addHours(string timestamp, int interval, string format?, string locale?)
addMinutes(string timestamp, int interval, string format?, string locale?)
toUpper(string input, string locale?)
toLower(string input, string locale?)
sentenceCase(string input, string locale?)
titleCase(string input, string locale?)

For all of these functions, locale parameter is optional. An locale paramter should be a valid locale string, such as "en-US", "en-GB", "fr-FR", "de-DE", "zh-CN", "ru-RU" etc.

Changed projects

  • AdaptiveExpressions
  • Microsoft.Bot.Builder.Dialogs.Adaptive
  • Microsoft.Bot.Builder.Dialogs
  • Microsoft.Bot.Builder.LanguageGeneration
  • Microsoft.Bot.Builder
  • AdaptiveExpressions.Tests
  • Microsoft.Bot.Builder.Dialogs.Adaptive.Templates.Tests
  • Microsoft.Bot.Builder.Tests

Metadata

Metadata

Assignees

Labels

Area: Adaptive expressionThe issue is related to Adaptive expressionsP0Must Fix. Release-blockerSize: MThe issue is not very complex and it is well understood, it will take 1 to 3 days to complete

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions