Make syntax localization util internal instead of private (#2663)

Working on some cleanup of localization code, and this utility is
duplicated in PA Client.
This commit is contained in:
McCall Saltzman 2024-09-30 11:43:53 -07:00 коммит произвёл GitHub
Родитель de16049af3
Коммит be19c3bf02
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 39 добавлений и 39 удалений

Просмотреть файл

@ -1,42 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Glue;
using Microsoft.PowerFx.Syntax;
using Microsoft.PowerFx.Types;
namespace Microsoft.PowerFx.Core
{
internal class ExpressionLocalizationHelper
{
internal static string ConvertExpression(string expressionText, RecordType parameters, BindingConfig bindingConfig, INameResolver resolver, IBinderGlue binderGlue, ParserOptions options, Features flags, bool toDisplay)
{
var targetLexer = toDisplay ? TexlLexer.GetLocalizedInstance(options?.Culture ?? CultureInfo.InvariantCulture) : TexlLexer.InvariantLexer;
var sourceLexer = toDisplay ? TexlLexer.InvariantLexer : TexlLexer.GetLocalizedInstance(options?.Culture ?? CultureInfo.InvariantCulture);
var worklist = GetLocaleSpecificTokenConversions(expressionText, sourceLexer, targetLexer);
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.PowerFx.Core.Binding;
using Microsoft.PowerFx.Core.Glue;
using Microsoft.PowerFx.Syntax;
using Microsoft.PowerFx.Types;
namespace Microsoft.PowerFx.Core
{
internal class ExpressionLocalizationHelper
{
internal static string ConvertExpression(string expressionText, RecordType parameters, BindingConfig bindingConfig, INameResolver resolver, IBinderGlue binderGlue, ParserOptions options, Features flags, bool toDisplay)
{
var targetLexer = toDisplay ? TexlLexer.GetLocalizedInstance(options?.Culture ?? CultureInfo.InvariantCulture) : TexlLexer.InvariantLexer;
var sourceLexer = toDisplay ? TexlLexer.InvariantLexer : TexlLexer.GetLocalizedInstance(options?.Culture ?? CultureInfo.InvariantCulture);
var worklist = GetLocaleSpecificTokenConversions(expressionText, sourceLexer, targetLexer);
var formula = new Formula(expressionText, toDisplay ? CultureInfo.InvariantCulture : options?.Culture ?? CultureInfo.InvariantCulture);
formula.EnsureParsed(options.GetParserFlags());
var binding = TexlBinding.Run(
binderGlue,
null,
new Core.Entities.QueryOptions.DataSourceToQueryOptionsMap(),
formula.ParseTree,
resolver,
bindingConfig,
ruleScope: parameters?._type,
updateDisplayNames: toDisplay,
forceUpdateDisplayNames: toDisplay,
features: flags);
foreach (var token in binding.NodesToReplace)
formula.EnsureParsed(options.GetParserFlags());
var binding = TexlBinding.Run(
binderGlue,
null,
new Core.Entities.QueryOptions.DataSourceToQueryOptionsMap(),
formula.ParseTree,
resolver,
bindingConfig,
ruleScope: parameters?._type,
updateDisplayNames: toDisplay,
forceUpdateDisplayNames: toDisplay,
features: flags);
foreach (var token in binding.NodesToReplace)
{
worklist.Add(token.Key.Span, TexlLexer.EscapeName(token.Value));
}
@ -49,7 +49,7 @@ namespace Microsoft.PowerFx.Core
return ConvertExpression(expressionText, parameters, bindingConfig, resolver, binderGlue, new ParserOptions() { Culture = culture }, flags, toDisplay);
}
private static IDictionary<Span, string> GetLocaleSpecificTokenConversions(string script, TexlLexer sourceLexer, TexlLexer targetLexer)
internal static IDictionary<Span, string> GetLocaleSpecificTokenConversions(string script, TexlLexer sourceLexer, TexlLexer targetLexer)
{
var worklist = new Dictionary<Span, string>();
@ -104,4 +104,4 @@ namespace Microsoft.PowerFx.Core
return worklist;
}
}
}
}