⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 286156 in webkit


Ignore:
Timestamp:
Nov 24, 2021, 5:39:10 PM (5 years ago)
Author:
ddkilzer@apple.com
Message:

Compiler should be able to check localized format strings for consistency
<https://webkit.org/b/232686>
<rdar://problem/84994345>

Reviewed by Darin Adler.

Source/WebCore:

The primary goal of this patch is to allow the compiler to check
format strings to ensure that the correct number and type of
arguments and placeholders are used. The epiphany to make this
possible was that Apple platforms may use CFStringRef objects or
const char* C-strings to accomplish this with CoreFoundation
macros. Non-Apple platforms continue to use const char* for
format strings to allow the compiler to check format strings.

To this end localized strings passed to formatLocalizedString()
must use a WEB_UI_FORMAT_*() macro on all platforms. Failure to
do so will result in a compiler error, though, since non-FORMAT
macros return a WTF::String.

This patch also eliminates autoreleased NSString objects except
when using WEB_UI_NSSTRING()/localizedNSString() directly (the
return value is always autoreleased), and it removes the need to
convert from CF/NSString -> WTF::String -> CF/NSString for
localized format strings.

  • Scripts/extract-localizable-strings.pl:

(isFormatMacro): Add.

  • Add support for parsing the following new macros with variadic parameter lists: o WEB_UI_FORMAT_STRING [cross-platform] o WEB_UI_FORMAT_CFSTRING o WEB_UI_FORMAT_CFSTRING_KEY
  • platform/LocalizedStrings.cpp:

(WebCore::formatLocalizedString):

  • Implement using CFStringRef format for Apple platforms, but const char* format for other platforms.
  • Use of these types allows format checking macros to be added to declarations in LocalizedStrings.h.

(WebCore::webCoreBundle): Add.

  • Extract code for getting a CFBundleRef for WebCore.framework into a function that's similar to webKitBundle() on Windows.

(WebCore::copyLocalizedString): Add.

  • This method was converted from localizedNSString() in LocalizedStringsCocoa.mm and from localizedString() in LocalizedStringsWin.cpp.

(WebCore::localizedString(CFStringRef)): Add.

  • Avoids runtime creation of CFStringRef on non-Windows platforms.

(WebCore::localizedString(const char*)):

  • Code for USE(CF) was converted from the same method in LocalizedStringsCocoa.mm, but only used on Windows port.

(WebCore::contextMenuItemTagLookUpInDictionary):
(WebCore::contextMenuItemTagTranslate):
(WebCore::multipleFileUploadText):
(WebCore::imageTitle):
(WebCore::localizedMediaTimeDescription):
(WebCore::validationMessageTooShortText):
(WebCore::validationMessageTooLongText):
(WebCore::validationMessageRangeUnderflowText):
(WebCore::validationMessageRangeOverflowText):
(WebCore::addTrackLabelAsSuffix):
(WebCore::addTextTrackKindClosedCaptionsSuffix):
(WebCore::addTextTrackKindCaptionsSuffix):
(WebCore::addTextTrackKindDescriptionsSuffix):
(WebCore::addTextTrackKindChaptersSuffix):
(WebCore::addTextTrackKindMetadataSuffix):
(WebCore::addTextTrackKindSDHSuffix):
(WebCore::addTextTrackKindEasyReaderSuffix):
(WebCore::addTextTrackKindForcedSuffix):
(WebCore::addAudioTrackKindDescriptionsSuffix):
(WebCore::addAudioTrackKindCommentarySuffix):
(WebCore::webCryptoMasterKeyKeychainLabel):
(WebCore::makeCredentialTouchIDPromptTitle):
(WebCore::getAssertionTouchIDPromptTitle):

  • Use WEB_UI_FORMAT_STRING() for cross-platform UI format strings, and use WEB_UI_FORMAT_CFSTRING[_KEY]() for Apple platform UI format strings.
  • Make formatLocalizedString() an implementation detail of WEB_UI_FORMAT_[CF]STRING() macros.
  • platform/LocalizedStrings.h:

(WEB_UI_STRING): Add.
(WEB_UI_STRING_KEY): Add.
(WEB_UI_STRING_WITH_MNEMONIC): Add.
(WEB_UI_CFSTRING): Add.
(WEB_UI_CFSTRING_KEY): Add.

  • Add USE(CF)-specific macros to avoid CFStringRef allocations at runtime. The Apple Windows port can not use these because it uses a default encoding of Mac Roman for CFSTR().

(WEB_UI_FORMAT_STRING): Add.

  • Cross-platform macro for UI format strings.
  • Note that non-USE(CF) macros essentially do nothing since localizedString() just converts const char* to WTF::String (which was previously converted back to const char*), and formatLocalizedString() now takes a const char*.

(WEB_UI_FORMAT_CFSTRING): Add.
(WEB_UI_FORMAT_CFSTRING_KEY): Add.

  • These macros are used as format string arguments to formatLocalizedString().

(WebCore::localizedFormatString): Add.

  • Declare a new function for USE(CF) that is passed to formatLocalizedString().

(WebCore::localizedString(CFStringRef)): Add.

  • Declare a new function for USE(CF) that takes a CFStringRef argument.

(WebCore::formatLocalizedString):

  • Change to use CFStringRef format for USE(CF) platforms (except Windows), and const char* format for other platforms so format macros may be added to the delaration.

(WebCore::localizedNSString):

  • Re-implement as an inline function using localizedString().
  • platform/cocoa/LocalizedStringsCocoa.mm:

(WebCore::localizedNSString): Delete.

  • Moved to LocalizedStrings.h.

(WebCore::localizedString): Delete.

  • Moved to LocalizedStrings.cpp.

(WebCore::contextMenuItemTagSearchWeb):
(WebCore::keygenKeychainItemName):
(WebCore::htmlSelectMultipleItems):

  • Switch from WEB_UI_STRING() to WEB_UI_FORMAT_CFSTRING() due to the new rule for localized format strings.

(WebCore::validationMessageTooLongText):

  • Switch from +[NSString stringWithFormat:] and WEB_UI_NSSTRING() to WebCore::formatLocalizedString() and WEB_UI_FORMAT_CFSTRING() for consistency.
  • platform/win/LocalizedStringsWin.cpp:

(WebCore::localizedString): Delete.

  • Moved to localizedString() in LocalizedStrings.cpp.

Source/WebCore/platform/gtk/po:

  • CMakeLists.txt:

(add_custom_command: xgettext):

  • Add WEB_UI_FORMAT_STRING to list of macros containing localizable strings.

Source/WebKitLegacy/mac:

  • Misc/WebLocalizableStringsInternal.mm:

(WebLocalizedStringInternal):

  • Use localizedNSString() instead of localizedString() to eliminate the need to convert from CFString -> String -> NSString.
Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r286152 r286156  
     12021-11-24  David Kilzer  <ddkilzer@apple.com>
     2
     3        Compiler should be able to check localized format strings for consistency
     4        <https://webkit.org/b/232686>
     5        <rdar://problem/84994345>
     6
     7        Reviewed by Darin Adler.
     8
     9        The primary goal of this patch is to allow the compiler to check
     10        format strings to ensure that the correct number and type of
     11        arguments and placeholders are used.  The epiphany to make this
     12        possible was that Apple platforms may use CFStringRef objects or
     13        const char* C-strings to accomplish this with CoreFoundation
     14        macros.  Non-Apple platforms continue to use const char* for
     15        format strings to allow the compiler to check format strings.
     16
     17        To this end localized strings passed to formatLocalizedString()
     18        must use a WEB_UI_FORMAT_*() macro on all platforms.  Failure to
     19        do so will result in a compiler error, though, since non-FORMAT
     20        macros return a WTF::String.
     21
     22        This patch also eliminates autoreleased NSString objects except
     23        when using WEB_UI_NSSTRING()/localizedNSString() directly (the
     24        return value is always autoreleased), and it removes the need to
     25        convert from CF/NSString -> WTF::String -> CF/NSString for
     26        localized format strings.
     27
     28        * Scripts/extract-localizable-strings.pl:
     29        (isFormatMacro): Add.
     30        - Add support for parsing the following new macros with variadic
     31          parameter lists:
     32          o WEB_UI_FORMAT_STRING  [cross-platform]
     33          o WEB_UI_FORMAT_CFSTRING
     34          o WEB_UI_FORMAT_CFSTRING_KEY
     35
     36        * platform/LocalizedStrings.cpp:
     37        (WebCore::formatLocalizedString):
     38        - Implement using `CFStringRef format` for Apple platforms, but
     39          `const char* format` for other platforms.
     40        - Use of these types allows format checking macros to be added
     41          to declarations in LocalizedStrings.h.
     42        (WebCore::webCoreBundle): Add.
     43        - Extract code for getting a CFBundleRef for WebCore.framework
     44          into a function that's similar to webKitBundle() on Windows.
     45        (WebCore::copyLocalizedString): Add.
     46        - This method was converted from localizedNSString() in
     47          LocalizedStringsCocoa.mm and from localizedString() in
     48          LocalizedStringsWin.cpp.
     49        (WebCore::localizedString(CFStringRef)): Add.
     50        - Avoids runtime creation of CFStringRef on non-Windows
     51          platforms.
     52        (WebCore::localizedString(const char*)):
     53        - Code for USE(CF) was converted from the same method in
     54          LocalizedStringsCocoa.mm, but only used on Windows port.
     55        (WebCore::contextMenuItemTagLookUpInDictionary):
     56        (WebCore::contextMenuItemTagTranslate):
     57        (WebCore::multipleFileUploadText):
     58        (WebCore::imageTitle):
     59        (WebCore::localizedMediaTimeDescription):
     60        (WebCore::validationMessageTooShortText):
     61        (WebCore::validationMessageTooLongText):
     62        (WebCore::validationMessageRangeUnderflowText):
     63        (WebCore::validationMessageRangeOverflowText):
     64        (WebCore::addTrackLabelAsSuffix):
     65        (WebCore::addTextTrackKindClosedCaptionsSuffix):
     66        (WebCore::addTextTrackKindCaptionsSuffix):
     67        (WebCore::addTextTrackKindDescriptionsSuffix):
     68        (WebCore::addTextTrackKindChaptersSuffix):
     69        (WebCore::addTextTrackKindMetadataSuffix):
     70        (WebCore::addTextTrackKindSDHSuffix):
     71        (WebCore::addTextTrackKindEasyReaderSuffix):
     72        (WebCore::addTextTrackKindForcedSuffix):
     73        (WebCore::addAudioTrackKindDescriptionsSuffix):
     74        (WebCore::addAudioTrackKindCommentarySuffix):
     75        (WebCore::webCryptoMasterKeyKeychainLabel):
     76        (WebCore::makeCredentialTouchIDPromptTitle):
     77        (WebCore::getAssertionTouchIDPromptTitle):
     78        - Use WEB_UI_FORMAT_STRING() for cross-platform UI format
     79          strings, and use WEB_UI_FORMAT_CFSTRING[_KEY]() for Apple
     80          platform UI format strings.
     81        - Make formatLocalizedString() an implementation detail of
     82          WEB_UI_FORMAT_[CF]STRING() macros.
     83
     84        * platform/LocalizedStrings.h:
     85        (WEB_UI_STRING): Add.
     86        (WEB_UI_STRING_KEY): Add.
     87        (WEB_UI_STRING_WITH_MNEMONIC): Add.
     88        (WEB_UI_CFSTRING): Add.
     89        (WEB_UI_CFSTRING_KEY): Add.
     90        - Add USE(CF)-specific macros to avoid CFStringRef allocations
     91          at runtime.  The Apple Windows port can not use these because
     92          it uses a default encoding of Mac Roman for CFSTR().
     93        (WEB_UI_FORMAT_STRING): Add.
     94        - Cross-platform macro for UI format strings.
     95        - Note that non-USE(CF) macros essentially do nothing since
     96          localizedString() just converts const char* to WTF::String
     97          (which was previously converted back to const char*), and
     98          formatLocalizedString() now takes a const char*.
     99        (WEB_UI_FORMAT_CFSTRING): Add.
     100        (WEB_UI_FORMAT_CFSTRING_KEY): Add.
     101        - These macros are used as format string arguments to
     102          formatLocalizedString().
     103        (WebCore::localizedFormatString): Add.
     104        - Declare a new function for USE(CF) that is passed to
     105          formatLocalizedString().
     106        (WebCore::localizedString(CFStringRef)): Add.
     107        - Declare a new function for USE(CF) that takes a CFStringRef
     108          argument.
     109        (WebCore::formatLocalizedString):
     110        - Change to use `CFStringRef format` for USE(CF) platforms
     111          (except Windows), and `const char* format` for other platforms
     112          so format macros may be added to the delaration.
     113        (WebCore::localizedNSString):
     114        - Re-implement as an inline function using localizedString().
     115
     116        * platform/cocoa/LocalizedStringsCocoa.mm:
     117        (WebCore::localizedNSString): Delete.
     118        - Moved to LocalizedStrings.h.
     119        (WebCore::localizedString): Delete.
     120        - Moved to LocalizedStrings.cpp.
     121        (WebCore::contextMenuItemTagSearchWeb):
     122        (WebCore::keygenKeychainItemName):
     123        (WebCore::htmlSelectMultipleItems):
     124        - Switch from WEB_UI_STRING() to WEB_UI_FORMAT_CFSTRING() due to
     125          the new rule for localized format strings.
     126        (WebCore::validationMessageTooLongText):
     127        - Switch from +[NSString stringWithFormat:] and
     128          WEB_UI_NSSTRING() to WebCore::formatLocalizedString() and
     129          WEB_UI_FORMAT_CFSTRING() for consistency.
     130
     131        * platform/win/LocalizedStringsWin.cpp:
     132        (WebCore::localizedString): Delete.
     133        - Moved to localizedString() in LocalizedStrings.cpp.
     134
    11352021-11-24  Said Abou-Hallawa  <said@apple.com>
    2136
  • trunk/Source/WebCore/Scripts/extract-localizable-strings.pl

    r278586 r286156  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2006, 2007, 2009, 2010, 2013 Apple Inc. All rights reserved.
     3# Copyright (C) 2006-2021 Apple Inc. All rights reserved.
    44#
    55# Redistribution and use in source and binary forms, with or without
     
    119119my @files = ( split "\n", `find $quotedDirectoriesString \\( -name "*.h" -o -name "*.m" -o -name "*.mm" -o -name "*.c" -o -name "*.cpp" \\)` );
    120120
     121sub isFormatMacro($) { return ($_[0] =~ /(WEB_)?UI_FORMAT_/); }
     122
    121123for my $file (sort @files) {
    122124    next if $file =~ /\/\w+LocalizableStrings\w*\.h$/ || $file =~ /\/LocalizedStrings\.h$/;
     
    134136    my $key;
    135137    my $comment;
     138    my $isFormat;
    136139    my $mnemonic;
    137140   
     
    187190                        $UIString = $string;
    188191                        $expected = ",";
    189                     } elsif (($macro =~ /(WEB_)?UI_(CF)?STRING_KEY(_INTERNAL)?$/) and !defined $key) {
     192                    } elsif (($macro =~ /(WEB_)?UI_(FORMAT_)?(CF)?STRING_KEY(_INTERNAL)?$/) and !defined $key) {
    190193                        # FIXME: Validate UTF-8 here?
    191194                        $key = $string;
     195                        $isFormat = isFormatMacro($macro);
    192196                        $expected = ",";
    193197                    } elsif (($macro =~ /WEB_UI_STRING_WITH_MNEMONIC$/) and !defined $mnemonic) {
    194198                        $mnemonic = $string;
     199                        $isFormat = 0;
    195200                        $expected = ",";
    196201                    } elsif (!defined $comment) {
     
    242247                }
    243248            } else {
    244                 if ($expected and $expected ne $token) {
     249                if ((!$isFormat and $expected and $expected ne $token) or ($isFormat and $expected eq ")" and $token ne ",")) {
    245250                    emitError($file, $., "found $token but expected $expected");
    246251                    $expected = "";
    247252                }
    248                 if (($token =~ /(WEB_)?UI_(CF)?STRING(_KEY)?(_INTERNAL)?$/) || ($token =~ /WEB_UI_NSSTRING$/) || ($token =~ /WEB_UI_STRING_WITH_MNEMONIC$/)) {
     253                if (($token =~ /(WEB_)?UI_(FORMAT_)?(CF)?STRING(_KEY)?(_INTERNAL)?$/) || ($token =~ /WEB_UI_NSSTRING$/) || ($token =~ /WEB_UI_STRING_WITH_MNEMONIC$/)) {
    249254                    $expected = "(";
    250255                    $macro = $token;
     
    254259                    $mnemonic = undef;
    255260                    $macroLine = $.;
     261                    $isFormat = isFormatMacro($token);
    256262                } elsif ($token eq "(" or $token eq "[") {
    257263                    ++$nestingLevel if defined $nestingLevel;
  • trunk/Source/WebCore/platform/LocalizedStrings.cpp

    r285234 r286156  
    11/*
    2  * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 Igalia S.L
    44 *
     
    3535
    3636#if USE(CF)
     37#if PLATFORM(WIN)
     38#include "WebCoreBundleWin.h"
     39#endif
    3740#include <wtf/RetainPtr.h>
    3841#endif
     
    4447namespace WebCore {
    4548
     49#if USE(CF) && !PLATFORM(WIN)
     50String formatLocalizedString(CFStringRef format, ...)
     51{
     52    va_list arguments;
     53    va_start(arguments, format);
     54
     55    auto localizedFormat = copyLocalizedString(format);
     56ALLOW_NONLITERAL_FORMAT_BEGIN
     57    // The 'format' parameter is already checked for correct placeholders and parameters.
     58    auto result = adoptCF(CFStringCreateWithFormatAndArguments(0, 0, localizedFormat.get(), arguments));
     59ALLOW_NONLITERAL_FORMAT_END
     60
     61    va_end(arguments);
     62    return result.get();
     63}
     64#else
    4665// Because |format| is used as the second parameter to va_start, it cannot be a reference
    4766// type according to section 18.7/3 of the C++ N1905 standard.
    48 String formatLocalizedString(String format, ...)
    49 {
    50 #if USE(CF)
     67String formatLocalizedString(const char* format, ...)
     68{
     69#if USE(CF) && PLATFORM(WIN)
     70    auto cfFormat = adoptCF(CFStringCreateWithCStringNoCopy(nullptr, format, kCFStringEncodingUTF8, kCFAllocatorNull));
    5171    va_list arguments;
    5272    va_start(arguments, format);
    53 
    54     ALLOW_NONLITERAL_FORMAT_BEGIN
    55     auto result = adoptCF(CFStringCreateWithFormatAndArguments(0, 0, format.createCFString().get(), arguments));
    56     ALLOW_NONLITERAL_FORMAT_END
    57 
     73    auto localizedFormat = copyLocalizedString(cfFormat.get());
     74    auto result = adoptCF(CFStringCreateWithFormatAndArguments(0, 0, localizedFormat.get(), arguments));
    5875    va_end(arguments);
    5976    return result.get();
     
    6178    va_list arguments;
    6279    va_start(arguments, format);
    63     GUniquePtr<gchar> result(g_strdup_vprintf(format.utf8().data(), arguments));
     80    GUniquePtr<gchar> result(g_strdup_vprintf(format, arguments));
    6481    va_end(arguments);
    6582    return String::fromUTF8(result.get());
     
    6986#endif
    7087}
    71 
    72 #if !USE(CF)
    73 
     88#endif
     89
     90#if USE(CF)
     91#if !PLATFORM(WIN)
     92static CFBundleRef webCoreBundle()
     93{
     94    static NeverDestroyed<RetainPtr<CFBundleRef>> bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebCore"));
     95    ASSERT(bundle.get());
     96    return bundle.get().get();
     97}
     98#endif
     99
     100RetainPtr<CFStringRef> copyLocalizedString(CFStringRef key)
     101{
     102#if !PLATFORM(IOS_FAMILY)
     103    // Can be called on a dispatch queue when initializing strings on iOS.
     104    // See LoadWebLocalizedStrings and <rdar://problem/7902473>.
     105    ASSERT(isMainThread());
     106#endif
     107
     108    static CFStringRef notFound = CFSTR("localized string not found");
     109
     110#if PLATFORM(WIN)
     111    CFBundleRef bundle = webKitBundle();
     112#else
     113    CFBundleRef bundle = webCoreBundle();
     114#endif
     115    auto result = adoptCF(CFBundleCopyLocalizedString(bundle, key, notFound, nullptr));
     116
     117#if ASSERT_ENABLED
     118    if (result.get() == notFound) {
     119        char keyCString[256];
     120        CFStringGetCString(key, keyCString, sizeof(keyCString), kCFStringEncodingUTF8);
     121        ASSERT_WITH_MESSAGE(result.get() != notFound, "Could not find localizable string '%s' in bundle", keyCString);
     122    }
     123#endif
     124
     125    return result;
     126}
     127#endif
     128
     129#if USE(CF) && !PLATFORM(WIN)
     130String localizedString(CFStringRef key)
     131{
     132    return copyLocalizedString(key).get();
     133}
     134#else
    74135String localizedString(const char* key)
    75136{
     137#if USE(CF)
     138    auto keyString = adoptCF(CFStringCreateWithCStringNoCopy(nullptr, key, kCFStringEncodingUTF8, kCFAllocatorNull));
     139    return copyLocalizedString(keyString.get()).get();
     140#else
    76141    return String::fromUTF8(key, strlen(key));
    77 }
    78 
     142#endif
     143}
    79144#endif
    80145
     
    234299#if USE(CF)
    235300    auto selectedCFString = truncatedStringForMenuItem(selectedString).createCFString();
    236     return formatLocalizedString(WEB_UI_CFSTRING("Look Up “%@”", "Look Up context menu item with selected word"), selectedCFString.get());
     301    return WEB_UI_FORMAT_CFSTRING("Look Up “%@”", "Look Up context menu item with selected word", selectedCFString.get());
    237302#elif USE(GLIB)
    238     return formatLocalizedString(WEB_UI_STRING("Look Up “%s”", "Look Up context menu item with selected word"), truncatedStringForMenuItem(selectedString).utf8().data());
     303    return WEB_UI_FORMAT_STRING("Look Up “%s”", "Look Up context menu item with selected word", truncatedStringForMenuItem(selectedString).utf8().data());
    239304#else
    240305    return WEB_UI_STRING("Look Up “<selection>”", "Look Up context menu item with selected word").replace("<selection>", truncatedStringForMenuItem(selectedString));
     
    247312{
    248313    auto selectedCFString = truncatedStringForMenuItem(selectedString).createCFString();
    249     return formatLocalizedString(WEB_UI_CFSTRING("Translate “%@”", "Translate context menu item with selected word"), selectedCFString.get());
     314    return WEB_UI_FORMAT_CFSTRING("Translate “%@”", "Translate context menu item with selected word", selectedCFString.get());
    250315}
    251316
     
    825890String multipleFileUploadText(unsigned numberOfFiles)
    826891{
    827     return formatLocalizedString(WEB_UI_STRING("%d files", "Label to describe the number of files selected in a file upload control that allows multiple files"), numberOfFiles);
     892    return WEB_UI_FORMAT_STRING("%d files", "Label to describe the number of files selected in a file upload control that allows multiple files", numberOfFiles);
    828893}
    829894
     
    847912    auto heightString = adoptCF(CFNumberFormatterCreateStringWithNumber(0, formatter.get(), height.get()));
    848913
    849     return formatLocalizedString(WEB_UI_CFSTRING("%@ %@×%@ pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename.createCFString().get(), widthString.get(), heightString.get());
     914    return WEB_UI_FORMAT_CFSTRING("%@ %@×%@ pixels", "window title for a standalone image (uses multiplication symbol, not x)", filename.createCFString().get(), widthString.get(), heightString.get());
    850915#elif USE(GLIB)
    851     return formatLocalizedString(WEB_UI_STRING("%s %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename.utf8().data(), size.width(), size.height());
     916    return WEB_UI_FORMAT_STRING("%s %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)", filename.utf8().data(), size.width(), size.height());
    852917#else
    853     return formatLocalizedString(WEB_UI_STRING("<filename> %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)"), size.width(), size.height()).replace("<filename>", filename);
     918    return WEB_UI_FORMAT_STRING("<filename> %d×%d pixels", "window title for a standalone image (uses multiplication symbol, not x)", size.width(), size.height()).replace("<filename>", filename);
    854919#endif
    855920}
     
    9731038
    9741039    if (days)
    975         return formatLocalizedString(WEB_UI_STRING("%1$d days %2$d hours %3$d minutes %4$d seconds", "accessibility help text for media controller time value >= 1 day"), days, hours, minutes, seconds);
     1040        return WEB_UI_FORMAT_STRING("%1$d days %2$d hours %3$d minutes %4$d seconds", "accessibility help text for media controller time value >= 1 day", days, hours, minutes, seconds);
    9761041    if (hours)
    977         return formatLocalizedString(WEB_UI_STRING("%1$d hours %2$d minutes %3$d seconds", "accessibility help text for media controller time value >= 60 minutes"), hours, minutes, seconds);
     1042        return WEB_UI_FORMAT_STRING("%1$d hours %2$d minutes %3$d seconds", "accessibility help text for media controller time value >= 60 minutes", hours, minutes, seconds);
    9781043    if (minutes)
    979         return formatLocalizedString(WEB_UI_STRING("%1$d minutes %2$d seconds", "accessibility help text for media controller time value >= 60 seconds"), minutes, seconds);
    980     return formatLocalizedString(WEB_UI_STRING("%1$d seconds", "accessibility help text for media controller time value < 60 seconds"), seconds);
     1044        return WEB_UI_FORMAT_STRING("%1$d minutes %2$d seconds", "accessibility help text for media controller time value >= 60 seconds", minutes, seconds);
     1045    return WEB_UI_FORMAT_STRING("%1$d seconds", "accessibility help text for media controller time value < 60 seconds", seconds);
    9811046}
    9821047
     
    10391104String validationMessageTooShortText(int, int minLength)
    10401105{
    1041     return formatLocalizedString(WEB_UI_STRING("Use at least %d characters", "Validation message for form control elements with a value shorter than minimum allowed length"), minLength);
     1106    return WEB_UI_FORMAT_STRING("Use at least %d characters", "Validation message for form control elements with a value shorter than minimum allowed length", minLength);
    10421107}
    10431108
     
    10451110String validationMessageTooLongText(int, int maxLength)
    10461111{
    1047     return formatLocalizedString(WEB_UI_STRING("Use no more than %d characters", "Validation message for form control elements with a value shorter than maximum allowed length"), maxLength);
     1112    return WEB_UI_FORMAT_STRING("Use no more than %d characters", "Validation message for form control elements with a value shorter than maximum allowed length", maxLength);
    10481113}
    10491114#endif
     
    10531118{
    10541119#if USE(CF)
    1055     return formatLocalizedString(WEB_UI_CFSTRING("Value must be greater than or equal to %@", "Validation message for input form controls with value lower than allowed minimum"), minimum.createCFString().get());
     1120    return WEB_UI_FORMAT_CFSTRING("Value must be greater than or equal to %@", "Validation message for input form controls with value lower than allowed minimum", minimum.createCFString().get());
    10561121#elif USE(GLIB)
    1057     return formatLocalizedString(WEB_UI_STRING("Value must be greater than or equal to %s", "Validation message for input form controls with value lower than allowed minimum"), minimum.utf8().data());
     1122    return WEB_UI_FORMAT_STRING("Value must be greater than or equal to %s", "Validation message for input form controls with value lower than allowed minimum", minimum.utf8().data());
    10581123#else
    10591124    UNUSED_PARAM(minimum);
     
    10651130{
    10661131#if USE(CF)
    1067     return formatLocalizedString(WEB_UI_CFSTRING("Value must be less than or equal to %@", "Validation message for input form controls with value higher than allowed maximum"), maximum.createCFString().get());
     1132    return WEB_UI_FORMAT_CFSTRING("Value must be less than or equal to %@", "Validation message for input form controls with value higher than allowed maximum", maximum.createCFString().get());
    10681133#elif USE(GLIB)
    1069     return formatLocalizedString(WEB_UI_STRING("Value must be less than or equal to %s", "Validation message for input form controls with value higher than allowed maximum"), maximum.utf8().data());
     1134    return WEB_UI_FORMAT_STRING("Value must be less than or equal to %s", "Validation message for input form controls with value higher than allowed maximum", maximum.utf8().data());
    10701135#else
    10711136    UNUSED_PARAM(maximum);
     
    11101175String addTrackLabelAsSuffix(const String& text, const String& label)
    11111176{
    1112     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ (%@)", "%@ (%@) (audio/text track)", "Audio/Text track display name format that includes the label and language of the track, in the form of 'Language (Label)'."), text.createCFString().get(), label.createCFString().get());
     1177    return WEB_UI_FORMAT_CFSTRING_KEY("%@ (%@)", "%@ (%@) (audio/text track)", "Audio/Text track display name format that includes the label and language of the track, in the form of 'Language (Label)'.", text.createCFString().get(), label.createCFString().get());
    11131178}
    11141179
     
    11221187    if (text.isEmpty())
    11231188        return textTrackKindClosedCaptionsDisplayName();
    1124     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ CC", "%@ CC (text track)", "Closed captions text track display name format that includes the language and/or locale (e.g. 'English CC')."), text.createCFString().get());
     1189    return WEB_UI_FORMAT_CFSTRING_KEY("%@ CC", "%@ CC (text track)", "Closed captions text track display name format that includes the language and/or locale (e.g. 'English CC').", text.createCFString().get());
    11251190}
    11261191
     
    11341199    if (text.isEmpty())
    11351200        return textTrackKindCaptionsDisplayName();
    1136     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Captions", "%@ Captions (text track)", "Captions text track display name format that includes the language and/or locale (e.g. 'English Captions')."), text.createCFString().get());
     1201    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Captions", "%@ Captions (text track)", "Captions text track display name format that includes the language and/or locale (e.g. 'English Captions').", text.createCFString().get());
    11371202}
    11381203
     
    11461211    if (text.isEmpty())
    11471212        return textTrackKindDescriptionsDisplayName();
    1148     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Descriptions", "%@ Descriptions (text track)", "Descriptions text track display name format that includes the language and/or locale (e.g. 'English Descriptions')."), text.createCFString().get());
     1213    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Descriptions", "%@ Descriptions (text track)", "Descriptions text track display name format that includes the language and/or locale (e.g. 'English Descriptions').", text.createCFString().get());
    11491214}
    11501215
     
    11581223    if (text.isEmpty())
    11591224        return textTrackKindChaptersDisplayName();
    1160     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Chapters", "%@ Chapters (text track)", "Chapters text track display name format that includes the language and/or locale (e.g. 'English Chapters')."), text.createCFString().get());
     1225    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Chapters", "%@ Chapters (text track)", "Chapters text track display name format that includes the language and/or locale (e.g. 'English Chapters').", text.createCFString().get());
    11611226}
    11621227
     
    11701235    if (text.isEmpty())
    11711236        return textTrackKindMetadataDisplayName();
    1172     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Metadata", "%@ Metadata (text track)", "Metadata text track display name format that includes the language and/or locale (e.g. 'English Metadata')."), text.createCFString().get());
     1237    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Metadata", "%@ Metadata (text track)", "Metadata text track display name format that includes the language and/or locale (e.g. 'English Metadata').", text.createCFString().get());
    11731238}
    11741239
     
    11821247    if (text.isEmpty())
    11831248        return textTrackKindSDHDisplayName();
    1184     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ SDH", "%@ SDH (text track)", "SDH (i.e. deaf and/or hard of hearing) text track display name format that includes the language and/or locale (e.g. 'English SDH')."), text.createCFString().get());
     1249    return WEB_UI_FORMAT_CFSTRING_KEY("%@ SDH", "%@ SDH (text track)", "SDH (i.e. deaf and/or hard of hearing) text track display name format that includes the language and/or locale (e.g. 'English SDH').", text.createCFString().get());
    11851250}
    11861251
     
    11941259    if (text.isEmpty())
    11951260        return textTrackKindEasyReaderDisplayName();
    1196     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Easy Reader", "%@ Easy Reader (text track)", "Easy Reader (i.e. 3rd-grade level) text track display name format that includes the language and/or locale (e.g. 'English Easy Reader')."), text.createCFString().get());
     1261    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Easy Reader", "%@ Easy Reader (text track)", "Easy Reader (i.e. 3rd-grade level) text track display name format that includes the language and/or locale (e.g. 'English Easy Reader').", text.createCFString().get());
    11971262}
    11981263
     
    12061271    if (text.isEmpty())
    12071272        return textTrackKindForcedDisplayName();
    1208     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Forced", "%@ Forced (text track)", "Forced text track display name format that includes the language and/or locale (e.g. 'English Forced')."), text.createCFString().get());
     1273    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Forced", "%@ Forced (text track)", "Forced text track display name format that includes the language and/or locale (e.g. 'English Forced').", text.createCFString().get());
    12091274}
    12101275
     
    12181283    if (text.isEmpty())
    12191284        return audioTrackKindDescriptionsDisplayName();
    1220     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Descriptions", "%@ Descriptions (audio track)", "Descriptions audio track display name format that includes the language and/or locale (e.g. 'English Descriptions')."), text.createCFString().get());
     1285    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Descriptions", "%@ Descriptions (audio track)", "Descriptions audio track display name format that includes the language and/or locale (e.g. 'English Descriptions').", text.createCFString().get());
    12211286}
    12221287
     
    12301295    if (text.isEmpty())
    12311296        return audioTrackKindCommentaryDisplayName();
    1232     return formatLocalizedString(WEB_UI_CFSTRING_KEY("%@ Commentary", "%@ Commentary (audio track)", "Commentary audio track display name format that includes the language and/or locale (e.g. 'English Commentary')."), text.createCFString().get());
     1297    return WEB_UI_FORMAT_CFSTRING_KEY("%@ Commentary", "%@ Commentary (audio track)", "Commentary audio track display name format that includes the language and/or locale (e.g. 'English Commentary').", text.createCFString().get());
    12331298}
    12341299
     
    12571322{
    12581323#if USE(CF)
    1259     return formatLocalizedString(WEB_UI_CFSTRING("%@ WebCrypto Master Key", "Name of application's single WebCrypto master key in Keychain"), localizedApplicationName.createCFString().get());
     1324    return WEB_UI_FORMAT_CFSTRING("%@ WebCrypto Master Key", "Name of application's single WebCrypto master key in Keychain", localizedApplicationName.createCFString().get());
    12601325#elif USE(GLIB)
    1261     return formatLocalizedString(WEB_UI_STRING("%s WebCrypto Master Key", "Name of application's single WebCrypto master key in Keychain"), localizedApplicationName.utf8().data());
     1326    return WEB_UI_FORMAT_STRING("%s WebCrypto Master Key", "Name of application's single WebCrypto master key in Keychain", localizedApplicationName.utf8().data());
    12621327#else
    12631328    return WEB_UI_STRING("<application> WebCrypto Master Key", "Name of application's single WebCrypto master key in Keychain").replace("<application>", localizedApplicationName);
     
    13331398String makeCredentialTouchIDPromptTitle(const String& bundleName, const String& domain)
    13341399{
    1335     return formatLocalizedString(WEB_UI_CFSTRING("“%@” would like to use Touch ID for “%@”.", "Allow the specified bundle to use Touch ID to sign in to the specified website on this device"), bundleName.createCFString().get(), domain.createCFString().get());
     1400    return WEB_UI_FORMAT_CFSTRING("“%@” would like to use Touch ID for “%@”.", "Allow the specified bundle to use Touch ID to sign in to the specified website on this device", bundleName.createCFString().get(), domain.createCFString().get());
    13361401}
    13371402
    13381403String getAssertionTouchIDPromptTitle(const String& bundleName, const String& domain)
    13391404{
    1340     return formatLocalizedString(WEB_UI_CFSTRING("“%@” would like to sign in to “%@”.", "Allow the specified bundle to sign in to the specified website"), bundleName.createCFString().get(), domain.createCFString().get());
     1405    return WEB_UI_FORMAT_CFSTRING("“%@” would like to sign in to “%@”.", "Allow the specified bundle to sign in to the specified website", bundleName.createCFString().get(), domain.createCFString().get());
    13411406}
    13421407
  • trunk/Source/WebCore/platform/LocalizedStrings.h

    r279164 r286156  
    11/*
    2  * Copyright (C) 2003-2020 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003-2021 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 Igalia S.L
    44 *
     
    2929
    3030#include <wtf/Forward.h>
     31
     32#ifdef __OBJC__
     33#include <wtf/cocoa/TypeCastsCocoa.h>
     34#endif
    3135
    3236#if USE(GLIB) && defined(GETTEXT_PACKAGE)
     
    378382#endif
    379383
    380 #if USE(GLIB) && defined(GETTEXT_PACKAGE)
     384#if USE(CF) && !PLATFORM(WIN)
     385#define WEB_UI_STRING(string, description) WebCore::localizedString(CFSTR(string))
     386#define WEB_UI_STRING_KEY(string, key, description) WebCore::localizedString(CFSTR(key))
     387#define WEB_UI_STRING_WITH_MNEMONIC(string, mnemonic, description) WebCore::localizedString(CFSTR(string))
     388#elif USE(GLIB) && defined(GETTEXT_PACKAGE)
    381389#define WEB_UI_STRING(string, description) WebCore::localizedString(_(string))
    382390#define WEB_UI_STRING_KEY(string, key, description) WebCore::localizedString(C_(key, string))
    383391#define WEB_UI_STRING_WITH_MNEMONIC(string, mnemonic, description) WebCore::localizedString(_(mnemonic))
    384392#else
     393// Work around default Mac Roman encoding of CFSTR() for Apple Windows port.
    385394#define WEB_UI_STRING(string, description) WebCore::localizedString(string)
    386395#define WEB_UI_STRING_KEY(string, key, description) WebCore::localizedString(key)
     
    390399#if USE(CF)
    391400// This is exactly as WEB_UI_STRING, but renamed to ensure the string is not scanned by non-CF ports.
     401#if PLATFORM(WIN)
     402// Work around default Mac Roman encoding of CFSTR() for Apple Windows port.
    392403#define WEB_UI_CFSTRING(string, description) WebCore::localizedString(string)
    393404#define WEB_UI_CFSTRING_KEY(string, key, description) WebCore::localizedString(key)
    394 #endif
    395 
     405#else
     406#define WEB_UI_CFSTRING(string, description) WebCore::localizedString(CFSTR(string))
     407#define WEB_UI_CFSTRING_KEY(string, key, description) WebCore::localizedString(CFSTR(key))
     408#endif
     409
     410    WEBCORE_EXPORT RetainPtr<CFStringRef> copyLocalizedString(CFStringRef key);
     411#endif
     412
     413#if USE(CF) && !PLATFORM(WIN)
     414    WEBCORE_EXPORT String localizedString(CFStringRef key);
     415#else
    396416    WEBCORE_EXPORT String localizedString(const char* key);
    397     String formatLocalizedString(String format, ...);
     417#endif
     418
     419#if USE(CF)
     420#if PLATFORM(WIN)
     421// Work around default Mac Roman encoding of CFSTR() for Apple Windows port.
     422#define WEB_UI_FORMAT_CFSTRING(string, description, ...) WebCore::formatLocalizedString(string, __VA_ARGS__)
     423#define WEB_UI_FORMAT_CFSTRING_KEY(string, key, description, ...) WebCore::formatLocalizedString(key, __VA_ARGS__)
     424#define WEB_UI_FORMAT_STRING(string, description, ...) WebCore::formatLocalizedString(string, __VA_ARGS__)
     425#else
     426#define WEB_UI_FORMAT_CFSTRING(string, description, ...) WebCore::formatLocalizedString(CFSTR(string), __VA_ARGS__)
     427#define WEB_UI_FORMAT_CFSTRING_KEY(string, key, description, ...) WebCore::formatLocalizedString(CFSTR(key), __VA_ARGS__)
     428#define WEB_UI_FORMAT_STRING(string, description, ...) WebCore::formatLocalizedString(CFSTR(string), __VA_ARGS__)
     429#endif // PLATFORM(WIN)
     430#elif USE(GLIB) && defined(GETTEXT_PACKAGE)
     431#define WEB_UI_FORMAT_STRING(string, description, ...) WebCore::formatLocalizedString(_(string), __VA_ARGS__)
     432#else
     433#define WEB_UI_FORMAT_STRING(string, description, ...) WebCore::formatLocalizedString(string, __VA_ARGS__)
     434#endif
     435
     436#if USE(CF) && !PLATFORM(WIN)
     437    String formatLocalizedString(CFStringRef format, ...) CF_FORMAT_FUNCTION(1, 2);
     438#else
     439    String formatLocalizedString(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
     440#endif
    398441
    399442#ifdef __OBJC__
    400443#define WEB_UI_NSSTRING(string, description) WebCore::localizedNSString(string)
    401     WEBCORE_EXPORT NSString *localizedNSString(NSString *key) NS_FORMAT_ARGUMENT(1);
     444    inline NS_FORMAT_ARGUMENT(1) NSString *localizedNSString(NSString *key)
     445    {
     446        return bridge_cast(copyLocalizedString(bridge_cast(key)).autorelease());
     447    }
    402448#endif
    403449
  • trunk/Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm

    r285234 r286156  
    11/*
    2  * Copyright (C) 2011-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636namespace WebCore {
    3737
    38 NSString *localizedNSString(NSString *key)
    39 {
    40 #if !PLATFORM(IOS_FAMILY)
    41     // Can be called on a dispatch queue when initializing strings on iOS.
    42     // See LoadWebLocalizedStrings and <rdar://problem/7902473>.
    43     ASSERT(isMainThread());
    44 #endif
    45 
    46     static NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"];
    47     return [bundle localizedStringForKey:key value:@"localized string not found" table:nullptr];
    48 }
    49 
    50 String localizedString(const char* key)
    51 {
    52     RetainPtr<CFStringRef> keyString = adoptCF(CFStringCreateWithCStringNoCopy(0, key, kCFStringEncodingUTF8, kCFAllocatorNull));
    53     return localizedNSString((__bridge NSString *)keyString.get());
    54 }
    55 
    5638String copyImageUnknownFileLabel()
    5739{
     
    8062{
    8163    auto searchProviderName = PAL::defaultSearchProviderDisplayName();
    82     return formatLocalizedString(WEB_UI_STRING("Search with %@", "Search with search provider context menu item with provider name inserted"), searchProviderName.get());
     64    return WEB_UI_FORMAT_CFSTRING("Search with %@", "Search with search provider context menu item with provider name inserted", searchProviderName.get());
    8365}
    8466
     
    234216String keygenKeychainItemName(const String& host)
    235217{
    236     return formatLocalizedString(WEB_UI_STRING("Key from %@", "Name of keychain key generated by the KEYGEN tag"), host.createCFString().get());
     218    return WEB_UI_FORMAT_CFSTRING("Key from %@", "Name of keychain key generated by the KEYGEN tag", host.createCFString().get());
    237219}
    238220
     
    246228        return WEB_UI_STRING("1 Item", "Present the element <select multiple> when a single <option> is selected (iOS only)");
    247229    default:
    248         return formatLocalizedString(WEB_UI_STRING("%zu Items", "Present the number of selected <option> items in a <select multiple> element (iOS only)"), count);
     230        return WEB_UI_FORMAT_CFSTRING("%zu Items", "Present the number of selected <option> items in a <select multiple> element (iOS only)", count);
    249231    }
    250232}
     
    279261String validationMessageTooLongText(int, int maxLength)
    280262{
    281     return [NSString localizedStringWithFormat:WEB_UI_NSSTRING(@"Use no more than %d character(s)", @"Validation message for form control elements with a value shorter than maximum allowed length"), maxLength];
     263    return WEB_UI_FORMAT_CFSTRING("Use no more than %d character(s)", "Validation message for form control elements with a value shorter than maximum allowed length", maxLength);
    282264}
    283265
  • trunk/Source/WebCore/platform/gtk/po/CMakeLists.txt

    r215718 r286156  
    2626            --keyword=_
    2727            --keyword=N_
     28            --keyword=WEB_UI_FORMAT_STRING:1
    2829            --keyword=WEB_UI_STRING:1
    2930            --keyword=WEB_UI_STRING_KEY:3c,1
  • trunk/Source/WebCore/platform/gtk/po/ChangeLog

    r282323 r286156  
     12021-11-24  David Kilzer  <ddkilzer@apple.com>
     2
     3        Compiler should be able to check localized format strings for consistency
     4        <https://webkit.org/b/232686>
     5        <rdar://problem/84994345>
     6
     7        Reviewed by Darin Adler.
     8
     9        * CMakeLists.txt:
     10        (add_custom_command: xgettext):
     11        - Add WEB_UI_FORMAT_STRING to list of macros containing
     12          localizable strings.
     13
    1142021-09-13  Piotr Drąg  <piotrdrag@gmail.com>
    215
  • trunk/Source/WebCore/platform/win/LocalizedStringsWin.cpp

    r238406 r286156  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#include "NotImplemented.h"
    30 #include "WebCoreInstanceHandle.h"
    31 #include <windows.h>
    32 #include <wtf/Assertions.h>
    33 #include <wtf/MainThread.h>
    34 #include <wtf/StdLibExtras.h>
    3530#include <wtf/text/WTFString.h>
    3631
    37 #if USE(CF)
    38 #include "WebCoreBundleWin.h"
    39 #include <CoreFoundation/CFBundle.h>
    40 #include <wtf/RetainPtr.h>
    41 #endif
    42 
    4332namespace WebCore {
    44 
    45 #if USE(CF)
    46 String localizedString(const char* key)
    47 {
    48     ASSERT(isMainThread());
    49 
    50     static CFStringRef notFound = CFSTR("localized string not found");
    51 
    52     RetainPtr<CFStringRef> keyString = adoptCF(CFStringCreateWithCStringNoCopy(NULL, key, kCFStringEncodingUTF8, kCFAllocatorNull));
    53     RetainPtr<CFStringRef> result = adoptCF(CFCopyLocalizedStringWithDefaultValue(keyString.get(), 0, webKitBundle(), notFound, 0));
    54     ASSERT_WITH_MESSAGE(result.get() != notFound, "could not find localizable string %s in bundle", key);
    55 
    56     return result.get();
    57 }
    58 #endif
    5933
    6034String uploadFileText()
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r285904 r286156  
     12021-11-24  David Kilzer  <ddkilzer@apple.com>
     2
     3        Compiler should be able to check localized format strings for consistency
     4        <https://webkit.org/b/232686>
     5        <rdar://problem/84994345>
     6
     7        Reviewed by Darin Adler.
     8
     9        * Misc/WebLocalizableStringsInternal.mm:
     10        (WebLocalizedStringInternal):
     11        - Use localizedNSString() instead of localizedString() to
     12          eliminate the need to convert from
     13          CFString -> String -> NSString.
     14
    1152021-11-16  Nikolaos Mouchtaris  <nmouchtaris@apple.com>
    216
  • trunk/Source/WebKitLegacy/mac/Misc/WebLocalizableStringsInternal.mm

    r95901 r286156  
    11/*
    2  * Copyright (C) 2011 Apple Inc. All rights reserved.
     2 * Copyright (C) 2011-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#import <WebCore/LocalizedStrings.h>
    29 #import <wtf/text/WTFString.h>
    3029
    3130using namespace WebCore;
     
    3332NSString *WebLocalizedStringInternal(const char* key)
    3433{
    35     return localizedString(key);
     34    auto keyString = adoptCF(CFStringCreateWithCStringNoCopy(0, key, kCFStringEncodingUTF8, kCFAllocatorNull));
     35    return localizedNSString(bridge_cast(keyString.get()));
    3636}
Note: See TracChangeset for help on using the changeset viewer.