interface ICoreWebView2ControllerOptions2
interface ICoreWebView2ControllerOptions2
: public ICoreWebView2ControllerOptions
This is the interface in ControllerOptions for ScriptLocale.
Summary
Members | Descriptions |
---|---|
get_ScriptLocale | The default locale for the WebView2. |
put_ScriptLocale | Sets the ScriptLocale property. |
Applies to
Product | Introduced |
---|---|
WebView2 Win32 | 1.0.1661.34 |
WebView2 Win32 Prerelease | 1.0.1671 |
Members
get_ScriptLocale
The default locale for the WebView2.
public HRESULT get_ScriptLocale(LPWSTR * locale)
It sets the default locale for all Intl JavaScript APIs and other JavaScript APIs that depend on it, namely Intl.DateTimeFormat()
which affects string formatting like in the time/date formats. Example: Intl.DateTimeFormat().format(new Date())
The intended locale value is in the format of BCP 47 Language Tags. More information can be found from IETF BCP47.
This property sets the locale for a CoreWebView2Environment used to create the WebView2ControllerOptions object, which is passed as a parameter in CreateCoreWebView2ControllerWithOptions
.
Changes to the ScriptLocale property apply to renderer processes created after the change. Any existing renderer processes will continue to use the previous ScriptLocale value. To ensure changes are applied to all renderer process, close and restart the CoreWebView2Environment and all associated WebView2 objects.
The default value for ScriptLocale will depend on the WebView2 language and OS region. If the language portions of the WebView2 language and OS region match, then it will use the OS region. Otherwise, it will use the WebView2 language.
OS Region | WebView2 Language | Default WebView2 ScriptLocale |
---|---|---|
en-GB | en-US | en-GB |
es-MX | en-US | en-US |
en-US | en-GB | en-US |
You can set the ScriptLocale to the empty string to get the default ScriptLocale value.
Use OS specific APIs to determine the OS region to use with this property if you want to match the OS. For example:
Win32 C++:
wchar_t osLocale[LOCALE_NAME_MAX_LENGTH] = {0};
GetUserDefaultLocaleName(osLocale, LOCALE_NAME_MAX_LENGTH);
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
wil::com_ptr<ICoreWebView2ControllerOptions2> webView2ControllerOptions2;
if (SUCCEEDED(options->QueryInterface(IID_PPV_ARGS(&webView2ControllerOptions2))))
{
if (m_webviewOption.useOSRegion)
{
wchar_t osLocale[LOCALE_NAME_MAX_LENGTH] = {0};
GetUserDefaultLocaleName(osLocale, LOCALE_NAME_MAX_LENGTH);
CHECK_FAILURE(webView2ControllerOptions2->put_ScriptLocale(osLocale));
}
else if (!m_webviewOption.scriptLocale.empty())
{
CHECK_FAILURE(webView2ControllerOptions2->put_ScriptLocale(
m_webviewOption.scriptLocale.c_str()));
}
}
put_ScriptLocale
Sets the ScriptLocale
property.
public HRESULT put_ScriptLocale(LPCWSTR locale)
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기