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

adding draft for locale api review #2925

Merged
merged 6 commits into from
Dec 6, 2022
Merged

Conversation

srwei
Copy link

@srwei srwei commented Nov 1, 2022

No description provided.

@srwei srwei requested a review from david-risney November 1, 2022 20:53
@david-risney david-risney added the API Proposal Review WebView2 API Proposal for review. label Nov 1, 2022
@srwei
Copy link
Author

srwei commented Nov 3, 2022

@david-risney
I'm thinking I should add an example or a reference to the Windows API that gets the OS region if they want to always use whatever is set in the OS. Would this be a good place to put it? or should I put this in the documentation in Microsoft.Web.WebView2.Core/documentation.md?

@david-risney
Copy link
Contributor

Yes. I would recommend updating the two samples in this doc (& in the sample apps)

@srwei
Copy link
Author

srwei commented Nov 3, 2022

Thanks. Updated here and in the .idl file.

* The intended value for `LocaleRegion` is in the format of `language[-country]` where `language` is the
2-letter code from [ISO 639](https://www.iso.org/iso-639-language-codes.html) and `country` is the
2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).
* By default, the `LocaleRegion` will be set as the value for the Limited option in the browser.
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not helpful to refer to the 'Limited option in the browser' since that won't be a known thing. We can just describe this on its own terms.

2-letter code from [ISO 639](https://www.iso.org/iso-639-language-codes.html) and `country` is the
2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).
* By default, the `LocaleRegion` will be set as the value for the Limited option in the browser.
That means that if the OS region and the display language share the same language code,
Copy link
Contributor

Choose a reason for hiding this comment

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

This info about the default value needs to be included in the ref docs below (the /// comments above the IDL method). Info in the ref docs doesn't need to be duplicated in the Description.

2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).
* By default, the `LocaleRegion` will be set as the value for the Limited option in the browser.
That means that if the OS region and the display language share the same language code,
like 'en-GB' and 'en-US', the value will be set to the OS region.
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to have a table of different options and the result. Something like the following (but with more rows) in the /// ref doc comments

OS Region WebView2 Language Default WebView2 LocaleRegion
en-GB en-US en-GB
... ... ...

Copy link
Author

Choose a reason for hiding this comment

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

Got it. Will add this as part of the experimental PR

/// The Windows API `GetLocaleInfoEx` can be used if the LocaleRegion value
/// is always set to match the OS region
///
/// ```cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of embedding the code directly, we generally use snippets syntax (see other APIs as examples) that will pull the snippet code out of the sample apps.

Copy link
Author

Choose a reason for hiding this comment

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

Was talking to @peiche-jessica about this, if the intention is not to include some particular code in the sample app but to have it for the reference doc (like usage of GetLocaleInfoEx), then shouldn't we add it here as a comment and then it will appear as code in the reference doc only?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its better to have it at least in the reference documentation, but generally we want to copy the sample code out of the sample app so end devs can easily try out the code or search and find the code on github. Why don't we want to include this sample code in the sample app?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be nice to complete these samples to show how you would actually use them with the property.

interface ICoreWebView2StagingControllerOptions : IUnknown {
/// Interface for locale region that is updated through the ControllerOptions
/// API.
/// The default region for WebView. It applies to browser UI such as
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it actually apply to browser UI? I thought it was only specific JavaScript APIs? Speaking of which, you should explicitly list the exact JavaScript APIs that are affected.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I might have been too general here. It affects the Intl.DateTimeFormat() Locale object which gets reflected in the UI for time/dates/other string formatting if it's used.

/// If V8 cannot find any matching locale on the input value, it will default
/// to the display language as the locale.
///
/// The Windows API `GetLocaleInfoEx` can be used if the LocaleRegion value
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rephrase to make this more OS independent like "Use OS specific APIs to determine the OS region to use with this property if you want to match the OS. For example in Windows you can use the GetLocaleInfoEx method."

Also, can we recommend the methods to use for .NET and WinRT? .NET is likely our most popular language.

// MSOWNERS: [email protected]
[propget] HRESULT LocaleRegion([out, retval] LPWSTR* locale);

/// Sets the `Region` property.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Sets the `Region` property.
/// Sets the `LocaleRegion` property.

```cpp
[uuid(0c9a374f-20c3-4e3c-a640-67b78a7e0a48), object, pointer_default(unique)]
interface ICoreWebView2StagingControllerOptions : IUnknown {
/// Interface for locale region that is updated through the ControllerOptions
Copy link
Contributor

Choose a reason for hiding this comment

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

This first sentence isn't really necessary - should be sort of implied by the ref doc which will include links, the name of the interface and so on.

interface ICoreWebView2StagingControllerOptions : IUnknown {
/// Interface for locale region that is updated through the ControllerOptions
/// API.
/// The default region for WebView. It applies to browser UI such as
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// The default region for WebView. It applies to browser UI such as
/// The default region for the WebView2. It applies to browser UI such as

@srwei srwei requested a review from david-risney November 14, 2022 21:07
/// The Windows API `GetLocaleInfoEx` can be used if the LocaleRegion value
/// is always set to match the OS region
///
/// ```cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Its better to have it at least in the reference documentation, but generally we want to copy the sample code out of the sample app so end devs can easily try out the code or search and find the code on github. Why don't we want to include this sample code in the sample app?

/// so changes will not be reflected in the existing webviews. They will need to closed
/// and reopened in order to see the changes reflected from using the new creation environment.
///
/// Validation is done on the V8 engine to match on the closest locale
Copy link
Contributor

Choose a reason for hiding this comment

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

Saying that the V8 engine is doing this isn't helpful unless how the V8 engine does it is well known or well documented. Otherwise you can just talk in terms of this API and how validation of the parameter is performed.

Copy link
Author

Choose a reason for hiding this comment

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

I spoke to the owner of the browser side and they said they think the validation processing is done by ICU. And linked me this to reference some documentation here: https://source.chromium.org/chromium/chromium/src/+/main:third_party/icu/source/common/unicode/locid.h
Is it okay to not mention the specific examples and just link to this? looking through the link, there's no concrete explanation of the matchign logic

/// and reopened in order to see the changes reflected from using the new creation environment.
///
/// Validation is done on the V8 engine to match on the closest locale
/// from the passed in locale region value. For example, passing in "en_gb"
Copy link
Contributor

Choose a reason for hiding this comment

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

This paragraph does not make it clear what is actually allowed or what validation is actually performed. It sounds like '_' is allowed instead of '-'? Are there many other things like that? Or is the _ syntax a different form language/country code format that we also accept and need to document? Is this the same as the syntax and validation performed for the Language property?

/// 639](https://www.iso.org/iso-639-language-codes.html) and `country` is the
/// 2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).
///
/// This property will update the environment creation. This is global and immutable,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Just wording suggestions

Suggested change
/// This property will update the environment creation. This is global and immutable,
/// This property sets the region for a CoreWebView2Environment during its creation.

/// 2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).
///
/// This property will update the environment creation. This is global and immutable,
/// so changes will not be reflected in the existing webviews. They will need to closed
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of global let's say that it applies to the environment and cannot be changed for that environment. (An app could have more than one environment so the property isn't global in that sense)

Suggested change
/// so changes will not be reflected in the existing webviews. They will need to closed
/// Creating a new CoreWebView2Environment object that connects to an already running browser process cannot
/// change the region previously set by an earlier CoreWebView2Environment. The CoreWebView2Environment
/// and all associated webview2 objects will need to closed

/// The Windows API `GetLocaleInfoEx` can be used if the LocaleRegion value
/// is always set to match the OS region
///
/// ```cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

Also it would be nice to complete these samples to show how you would actually use them with the property.

2-letter code from [ISO 3166](https://www.iso.org/standard/72482.html).

# Examples
```cpp
Copy link
Contributor

Choose a reason for hiding this comment

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

The two examples in C++ & C# should do the same thing. Here the C++ just sets up the controller options, and the C# one also calls create async, and setapplocale

@srwei
Copy link
Author

srwei commented Nov 22, 2022

@david-risney created a PR to include an option to use OSRegion for the LocaleRegion value in the SampleApp. Because it's now part of the code snippet, do I still need to include the examples in the comments for c++ and c#?
PR link: https://microsoft.visualstudio.com/Edge/_git/chromium.src/pullrequest/8154109

@srwei srwei requested a review from david-risney November 29, 2022 18:41
@srwei srwei merged commit a128202 into api-locale-region Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Proposal Review WebView2 API Proposal for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants