Skip to content

Commit

Permalink
Multiple locale support for winget workflows (#903)
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-msft authored May 1, 2021
1 parent 9399b6a commit 558f3f4
Show file tree
Hide file tree
Showing 43 changed files with 925 additions and 62 deletions.
10 changes: 10 additions & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ authz
autocomplete
auxdata
azureedge
bcp
bcp47
bcrypt
binver
Bitmask
Expand All @@ -50,6 +52,7 @@ cnt
codepage
COMMANDBARFLYOUT
Commandline
comparand
conemu
config
Configurability
Expand Down Expand Up @@ -95,6 +98,7 @@ dll
dllexport
docx
dotnet
downlevel
downloader
dword
DWORDLONG
Expand Down Expand Up @@ -203,6 +207,9 @@ json
junit
langutil
lastwritetime
LCID
LCIDTo
LEN
Linux
LLVM
llvmorg
Expand Down Expand Up @@ -232,6 +239,7 @@ MINORVERSION
mkdir
monostate
motw
mrm
msbuild
msdata
MSDN
Expand Down Expand Up @@ -373,6 +381,7 @@ simplesave
simpletest
sizeof
sln
SNAME
snprintf
sourced
Specv
Expand Down Expand Up @@ -537,3 +546,4 @@ XTOKEN
yaml
yml
yy
zh
12 changes: 12 additions & 0 deletions doc/Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ The `scope` behavior affects the choice between installing a package for the cur
},
```

### Locale

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

```json
"installBehavior": {
"preferences": {
"locale": [ "en-US", "fr-FR" ]
}
},
```

## Telemetry

The `telemetry` settings control whether winget writes ETW events that may be sent to Microsoft on a default installation of Windows.
Expand Down
11 changes: 11 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
"machine"
],
"default": "user"
},
"locale": {
"description": "The locales of a package install",
"type": "array",
"items": {
"type": "string",
"pattern": "^([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]{1,8})(-[a-zA-Z]{1,8})*$",
"maxLength": 20
},
"minItems": 1,
"maxItems": 10
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ namespace AppInstaller::CLI
return Argument{ "interactive", 'i', Args::Type::Interactive, Resource::String::InteractiveArgumentDescription, ArgumentType::Flag };
case Args::Type::Silent:
return Argument{ "silent", 'h', Args::Type::Silent, Resource::String::SilentArgumentDescription, ArgumentType::Flag };
case Args::Type::Language:
return Argument{ "lang", 'a', Args::Type::Language, Resource::String::LanguageArgumentDescription, ArgumentType::Standard, Argument::Visibility::Hidden };
case Args::Type::Locale:
return Argument{ "locale", NoAlias, Args::Type::Locale, Resource::String::LocaleArgumentDescription, ArgumentType::Standard };
case Args::Type::Log:
return Argument{ "log", 'o', Args::Type::Log, Resource::String::LogArgumentDescription, ArgumentType::Standard };
case Args::Type::Override:
Expand Down
12 changes: 10 additions & 2 deletions src/AppInstallerCLICore/Commands/InstallCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace AppInstaller::CLI
Argument::ForType(Args::Type::Exact),
Argument::ForType(Args::Type::Interactive),
Argument::ForType(Args::Type::Silent),
Argument::ForType(Args::Type::Language),
Argument::ForType(Args::Type::Locale),
Argument::ForType(Args::Type::Log),
Argument::ForType(Args::Type::Override),
Argument::ForType(Args::Type::InstallLocation),
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace AppInstaller::CLI
context <<
Workflow::CompleteWithSingleSemanticsForValue(valueType);
break;
case Args::Type::Language:
case Args::Type::Locale:
// May well move to CompleteWithSingleSemanticsForValue,
// but for now output nothing.
context <<
Expand Down Expand Up @@ -107,6 +107,14 @@ namespace AppInstaller::CLI
throw CommandException(Resource::String::InvalidArgumentValueError, s_ArgumentName_Scope, { "user"_lis, "machine"_lis });
}
}

if (execArgs.Contains(Args::Type::Locale))
{
if (!Locale::IsWellFormedBcp47Tag(execArgs.GetArg(Args::Type::Locale)))
{
throw CommandException(Resource::String::InvalidArgumentValueErrorWithoutValidValues, Argument::ForType(Args::Type::Locale).Name(), {});
}
}
}

void InstallCommand::ExecuteInternal(Context& context) const
Expand Down
7 changes: 0 additions & 7 deletions src/AppInstallerCLICore/Commands/UpgradeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ namespace AppInstaller::CLI
Argument::ForType(Args::Type::Exact),
Argument::ForType(Args::Type::Interactive),
Argument::ForType(Args::Type::Silent),
Argument::ForType(Args::Type::Language),
Argument::ForType(Args::Type::Log),
Argument::ForType(Args::Type::Override),
Argument::ForType(Args::Type::InstallLocation),
Expand Down Expand Up @@ -88,12 +87,6 @@ namespace AppInstaller::CLI
context <<
Workflow::CompleteWithSingleSemanticsForValueUsingExistingSource(valueType);
break;
case Execution::Args::Type::Language:
// May well move to CompleteWithSingleSemanticsForValue,
// but for now output nothing.
context <<
Workflow::CompleteWithEmptySet;
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AppInstaller::CLI::Execution
// Install behavior
Interactive,
Silent,
Language,
Locale,
Log,
Override, //Override args are (and the only args) directly passed to installer
InstallLocation,
Expand Down
4 changes: 2 additions & 2 deletions src/AppInstallerCLICore/ExecutionContextData.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace AppInstaller::CLI::Execution
Max
};

struct PackagesToInstall
struct PackageToInstall
{
std::shared_ptr<Repository::IPackageVersion> PackageVersion;
PackageCollection::Package PackageRequest;
Expand Down Expand Up @@ -169,7 +169,7 @@ namespace AppInstaller::CLI::Execution
template <>
struct DataMapping<Data::PackagesToInstall>
{
using value_t = std::vector<PackagesToInstall>;
using value_t = std::vector<PackageToInstall>;
};

template <>
Expand Down
3 changes: 2 additions & 1 deletion src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,14 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(InvalidAliasError);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidArgumentSpecifierError);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidArgumentValueError);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidArgumentValueErrorWithoutValidValues);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidJsonFile);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidNameError);
WINGET_DEFINE_RESOURCE_STRINGID(LanguageArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(LicenseAgreement);
WINGET_DEFINE_RESOURCE_STRINGID(Links);
WINGET_DEFINE_RESOURCE_STRINGID(ListCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ListCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(LocaleArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(LocationArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(LogArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(Logs);
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/ImportExportFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace AppInstaller::CLI::Workflow
void SearchPackagesForImport(Execution::Context& context)
{
const auto& sources = context.Get<Execution::Data::Sources>();
std::vector<Execution::PackagesToInstall> packagesToInstall = {};
std::vector<Execution::PackageToInstall> packagesToInstall = {};
bool foundAll = true;

// Look for the packages needed from each source independently.
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/InstallFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ namespace AppInstaller::CLI::Workflow
toLog ? static_cast<std::string>(toLog->GetProperty(PackageVersionProperty::Name)) : "",
toLog ? static_cast<std::string>(toLog->GetProperty(PackageVersionProperty::Version)) : "",
toLog ? static_cast<std::string_view>(toLogMetadata[PackageVersionMetadata::Publisher]) : "",
toLog ? static_cast<std::string_view>(toLogMetadata[PackageVersionMetadata::Locale]) : ""
toLog ? static_cast<std::string_view>(toLogMetadata[PackageVersionMetadata::InstalledLocale]) : ""
);
}
}
Expand Down
Loading

0 comments on commit 558f3f4

Please sign in to comment.