[webkit-changes] [WebKit/WebKit] 5cb898: Web Extensions fail to load Chinese localizations.

Timothy Hatcher noreply at github.com
Wed Oct 23 19:22:06 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 5cb898d5fbec7dca0ad41e125b5be9199cc2175d
      https://github.com/WebKit/WebKit/commit/5cb898d5fbec7dca0ad41e125b5be9199cc2175d
  Author: Timothy Hatcher <timothy at apple.com>
  Date:   2024-10-23 (Wed, 23 Oct 2024)

  Changed paths:
    M Source/WTF/wtf/Language.cpp
    M Source/WTF/wtf/Language.h
    M Source/WTF/wtf/cocoa/LanguageCocoa.mm
    M Source/WebCore/en.lproj/Localizable.strings
    M Source/WebKit/Shared/Extensions/_WKWebExtensionLocalization.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebExtension.mm
    M Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm
    M Source/WebKit/UIProcess/Extensions/WebExtension.cpp
    M Source/WebKit/UIProcess/Extensions/WebExtension.h
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPILocalization.mm

  Log Message:
  -----------
  Web Extensions fail to load Chinese localizations.
https://webkit.org/b/281928
rdar://problem/138435009

Reviewed by Brian Weinstein.

* Improve best match logic by using `indexOfBestMatchingLanguageInList()` with the extension's
  supported locales. This properly handles Chinese script codes.
* Add error handling for `default_locale` by validating it against the locales provided in the
  extension's `_locales` directory.

* Source/WTF/wtf/Language.cpp:
(WTF::canonicalLanguageIdentifier): Simplified to handle more than 2 parts.
(WTF::parseLocale): Added.
(WTF::indexOfBestMatchingLanguageInList): Simplified and use canonicalized input.
* Source/WTF/wtf/Language.h:
* Source/WTF/wtf/cocoa/LanguageCocoa.mm:
(WTF::parseLocale): Added.
* Source/WebCore/en.lproj/Localizable.strings: Updated.
* Source/WebKit/Shared/Extensions/_WKWebExtensionLocalization.mm:
(-[_WKWebExtensionLocalization initWithWebExtension:]): Use new helpers from WebExtension
to load the three possible localization dictionaries.
* Source/WebKit/UIProcess/API/Cocoa/WKWebExtension.mm:
(-[WKWebExtension defaultLocale]): Make the `NSLocale` here.
* Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm:
(WebKit::WebExtension::parseManifest): Add error handling for `default_locale`.
(WebKit::WebExtension::preferredSystemLocales): Added.
(WebKit::WebExtension::parseLocale): Added.
(WebKit::WebExtension::defaultLocale): Deleted.
* Source/WebKit/UIProcess/Extensions/WebExtension.cpp:
(WebKit::toAPI): Added InvalidDefaultLocale error.
(WebKit::WebExtension::createError): Ditto.
(WebKit::WebExtension::supportedLocales): Added.
(WebKit::WebExtension::defaultLocale): Added.
(WebKit::WebExtension::bestMatchLocale): Added.
* Source/WebKit/UIProcess/Extensions/WebExtension.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm:
(TestWebKitAPI::TEST(WKWebExtension, DefaultLocaleParsing)): Added.
* Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPILocalization.mm:
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nWithFallback)): Force `en-US` to match expectations.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseSimplified)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseSimplifiedOnly)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseSimplifiedScript)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseTraditional)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseSimplifiedInTaiwan)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseTraditionalInChina)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseSimplifiedInHongKong)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseTraditionalOnly)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseTraditionalScript)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nChineseLanguageFallback)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseBrazilian)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseEuropean)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseUnitedStates)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseUnitedStatesFallbackToBrazilian)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseUnitedStatesFallbackToGeneric)): Added.
(TestWebKitAPI::TEST(WKWebExtensionAPILocalization, i18nPortugueseLanguageFallback)): Added.

Canonical link: https://commits.webkit.org/285633@main



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list