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

Multiple locale support for winget workflows #903

Merged
merged 12 commits into from
May 1, 2021

Conversation

yao-msft
Copy link
Contributor

@yao-msft yao-msft commented Apr 26, 2021

Change

This change implements support for multi locale in winget workflows.

  • Exposed locale option in command line as a requirement
  • Exposed locale option in winget settings as requirement/preference similar to how Scope works
  • Installer selection uses both locale requirement or preference if applicable
  • Manifest localization merging(for show) only use locale preference

Validation

  • Added tests for workflows and ManifestComparato
  • Tried local run and works as expected
Microsoft Reviewers: Open in CodeFlow

@yao-msft yao-msft requested a review from a team as a code owner April 26, 2021 21:07
@github-actions
Copy link

Misspellings found, please review:

  • bcp
  • LCIDTo
To accept these changes, run the following commands from this repository on this branch
pushd $(git rev-parse --show-toplevel)
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"Langs sourc "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
make_path ".github/actions/spelling";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"bcp langs LCIDTo "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
popd

@github-actions
Copy link

Misspellings found, please review:

  • LCIDTo
To accept these changes, run the following commands from this repository on this branch
pushd $(git rev-parse --show-toplevel)
perl -e '
my @expect_files=qw('".github/actions/spelling/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"Langs sourc "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spelling/expect.txt";
use File::Path qw(make_path);
make_path ".github/actions/spelling";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"langs LCIDTo "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
popd

doc/Settings.md Outdated

The `locale` behavior affects the choice of installer based on installer locale. The matching parameter is `--locale`, and uses bcp47 language tag.

Note the locale preference will also be applied to `winget show` command if applicable.
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 29, 2021

Choose a reason for hiding this comment

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

Should they? It feels like a separate setting should exist for display language. #Closed

{
if (!Utility::IsWellFormedBcp47Tag(execArgs.GetArg(Args::Type::Locale)))
{
throw CommandException(Resource::String::InvalidArgumentValueError, s_ArgumentName_Locale, { "bcp47 language tags"_lis });
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 29, 2021

Choose a reason for hiding this comment

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

s_ArgumentName_Locale

If the Arg is defined in another file, this value should come from finding the Arg and using it's name. #Closed

{
if (!Utility::IsWellFormedBcp47Tag(execArgs.GetArg(Args::Type::Locale)))
{
throw CommandException(Resource::String::InvalidArgumentValueError, s_ArgumentName_Locale, { "bcp47 language tags"_lis });
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

"bcp47 language tags"

This is not a localization independent string and it wouldn't fit well into this exception constructor anyway. I think it should just be dropped so the user gets "invalid arg: locale" and can go look at the help on that. #Closed

<data name="LanguageArgumentDescription" xml:space="preserve">
<value>Language to install (if supported)</value>
<data name="LocaleArgumentDescription" xml:space="preserve">
<value>Locale to install (if supported)</value>
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

Locale to install (if supported)

What about: Locale to use (BCP 47 format) #Closed

if (!preferredList.empty())
{
// TODO: we only take the first one for now
preference = preferredList.at(0);
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

This suggests that the setting should also be an array. What are the complications with taking the whole list? The only one that comes to mind is that the sort is harder, but I don't think that is insurmountable. #Closed

#include <string>
#include <vector>

namespace AppInstaller::Utility
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

Utility

Locale? #Closed

if (!preferredList.empty())
{
// TODO: we only take the first one for now
targetLocale = preferredList.at(0);
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

targetLocale = preferredList.at(0);

As discussed, we should use all of these languages and only these for now. #Closed

@@ -15,42 +15,42 @@ namespace AppInstaller::Repository::Microsoft
struct ARPHelper
{
// See https://docs.microsoft.com/en-us/windows/win32/msi/uninstall-registry-key for details.
std::wstring SubKeyPath{ L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" };
inline static const std::wstring SubKeyPath{ L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall" };
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

static

Please revert to instance. #Closed

@JohnMcPMS
Copy link
Member

JohnMcPMS commented Apr 30, 2021

            result += m_requirement;

is not one of: en-us, es-mx, etc. ?


In reply to: 830410192


In reply to: 830410192


Refers to: src/AppInstallerCLICore/Workflows/ManifestComparator.cpp:316 in aa5db9b. [](commit_id = aa5db9b, deletion_comment = True)

double firstScore = first.Locale.empty() ? Locale::UnknownLanguageDistanceScore : Locale::GetDistanceOfLanguage(preferredLocale, first.Locale);
double secondScore = second.Locale.empty() ? Locale::UnknownLanguageDistanceScore : Locale::GetDistanceOfLanguage(preferredLocale, second.Locale);

if (firstScore > secondScore && firstScore >= Locale::MinimumDistanceScoreAsCompatibleMatch)
Copy link
Member

@JohnMcPMS JohnMcPMS Apr 30, 2021

Choose a reason for hiding this comment

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

if (firstScore > secondScore && firstScore >= Locale::MinimumDistanceScoreAsCompatibleMatch)

The search through m_preference needs to stop whenever either score is compatible. So:

if (firstScore >= Compat || secondScore => Compat)
  return firstScore > secondScore;

This is required or you could have IsFirstBetter return true for both orderings of first and second. #Closed

Copy link
Member

@JohnMcPMS JohnMcPMS left a comment

Choose a reason for hiding this comment

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

:shipit:

@yao-msft yao-msft merged commit 558f3f4 into microsoft:master May 1, 2021
@yao-msft yao-msft deleted the multilocale branch May 1, 2021 00:47
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.

None yet

2 participants