Make it possible to use WEB_UI_STRING macros to mark translatable strings in glib based ports
https://bugs.webkit.org/show_bug.cgi?id=169672
Reviewed by Michael Catanzaro.
Source/WebCore:
WEB_UI_STRING macros are currently used by Cocoa based ports and Windows port. For other ports it simply returns
the given string, but it's not translated. In the GTK+ port we have all translatable strings from
LocalizedStrings.cpp copied in LocalizedStringsGtk.cpp to use the glib macros to mark them as translatable. In
most of the cases the strings are exactly in the same, in some others (the context menu ones) the string only
differs in the mnemonics used by GTK, and only in a few cases the strings are different. We could remove most of
that duplication if strings used by WEB_UI_STRING were marked as translatable in glib based ports too.
This patch makes that possible with the following changes:
- Add WEB_UI_STRING_WITH_MNEMONIC() to handle the cases where the strings only differ in the mnemonics. It
receives the string with mnemonics that is ignored in all ports except GTK+.
- All platform specific strings have been moved to the platform files, to ensure scanners don't include
strings from other ports.
- For the same reason a new macro WEB_UI_CFSTRING has been also added, just to make sure that CF strings are
only used by CF based ports. The implementation is the same as WEB_UI_STRING, it only changes the name to
not confuse the scanners.
- And again for the same reason, for non-CF and non-Glib cases WEB_UI_STRING is not used, since in those cases
strings are not really translated and String::fromUTF8() is actually used. So, now we use String::fromUTF8()
directly instead of WEB_UI_STRING to not confuse the scanners.
* CMakeLists.txt: Add LocalizedStrings.cpp to the compilation.
* PlatformGTK.cmake: Move LocalizedStringsGtk.cpp to the list of sources not depending on GTK+, since it no
longer uses GTK+.
* extract-localizable-strings.pl: Update it to handle the new macros.
* platform/LocalizedStrings.cpp:
(WebCore::formatLocalizedString):
(WebCore::contextMenuItemTagOpenLinkInNewWindow):
(WebCore::contextMenuItemTagDownloadLinkToDisk):
(WebCore::contextMenuItemTagOpenImageInNewWindow):
(WebCore::contextMenuItemTagCopyImageToClipboard):
(WebCore::contextMenuItemTagOpenFrameInNewWindow):
(WebCore::contextMenuItemTagCopy):
(WebCore::contextMenuItemTagGoBack):
(WebCore::contextMenuItemTagGoForward):
(WebCore::contextMenuItemTagStop):
(WebCore::contextMenuItemTagReload):
(WebCore::contextMenuItemTagCut):
(WebCore::contextMenuItemTagPaste):
(WebCore::contextMenuItemTagIgnoreSpelling):
(WebCore::contextMenuItemTagLearnSpelling):
(WebCore::contextMenuItemTagLookUpInDictionary):
(WebCore::contextMenuItemTagOpenLink):
(WebCore::contextMenuItemTagIgnoreGrammar):
(WebCore::contextMenuItemTagSpellingMenu):
(WebCore::contextMenuItemTagShowSpellingPanel):
(WebCore::contextMenuItemTagCheckSpelling):
(WebCore::contextMenuItemTagCheckSpellingWhileTyping):
(WebCore::contextMenuItemTagCheckGrammarWithSpelling):
(WebCore::contextMenuItemTagFontMenu):
(WebCore::contextMenuItemTagBold):
(WebCore::contextMenuItemTagItalic):
(WebCore::contextMenuItemTagUnderline):
(WebCore::contextMenuItemTagOutline):
(WebCore::contextMenuItemTagOpenVideoInNewWindow):
(WebCore::contextMenuItemTagOpenAudioInNewWindow):
(WebCore::contextMenuItemTagDownloadVideoToDisk):
(WebCore::contextMenuItemTagDownloadAudioToDisk):
(WebCore::contextMenuItemTagExitVideoFullscreen):
(WebCore::contextMenuItemTagMediaPlay):
(WebCore::contextMenuItemTagMediaPause):
(WebCore::contextMenuItemTagMediaMute):
(WebCore::contextMenuItemTagInspectElement):
(WebCore::AXAutoFillContactsLabel):
(WebCore::imageTitle):
(WebCore::validationMessageRangeUnderflowText):
(WebCore::validationMessageRangeOverflowText):
(WebCore::textTrackCountryAndLanguageMenuItemText):
(WebCore::textTrackLanguageMenuItemText):
(WebCore::closedCaptionTrackMenuItemText):
(WebCore::sdhTrackMenuItemText):
(WebCore::easyReaderTrackMenuItemText):
(WebCore::forcedTrackMenuItemText):
(WebCore::audioDescriptionTrackSuffixText):
(WebCore::webCryptoMasterKeyKeychainLabel):
* platform/LocalizedStrings.h:
* platform/cocoa/LocalizedStringsCocoa.mm:
(WebCore::copyImageUnknownFileLabel):
(WebCore::contextMenuItemTagSearchInSpotlight):
(WebCore::contextMenuItemTagSearchWeb):
(WebCore::contextMenuItemTagShowFonts):
(WebCore::contextMenuItemTagStyles):
(WebCore::contextMenuItemTagShowColors):
(WebCore::contextMenuItemTagSpeechMenu):
(WebCore::contextMenuItemTagStartSpeaking):
(WebCore::contextMenuItemTagStopSpeaking):
(WebCore::contextMenuItemTagCorrectSpellingAutomatically):
(WebCore::contextMenuItemTagSubstitutionsMenu):
(WebCore::contextMenuItemTagShowSubstitutions):
(WebCore::contextMenuItemTagSmartCopyPaste):
(WebCore::contextMenuItemTagSmartQuotes):
(WebCore::contextMenuItemTagSmartDashes):
(WebCore::contextMenuItemTagSmartLinks):
(WebCore::contextMenuItemTagTextReplacement):
(WebCore::contextMenuItemTagTransformationsMenu):
(WebCore::contextMenuItemTagMakeUpperCase):
(WebCore::contextMenuItemTagMakeLowerCase):
(WebCore::contextMenuItemTagCapitalize):
(WebCore::contextMenuItemTagChangeBack):
(WebCore::contextMenuItemTagEnterVideoEnhancedFullscreen):
(WebCore::contextMenuItemTagExitVideoEnhancedFullscreen):
(WebCore::AXARIAContentGroupText):
(WebCore::AXHorizontalRuleDescriptionText):
(WebCore::AXMarkText):
(WebCore::AXMeterGaugeRegionOptimumText):
(WebCore::AXMeterGaugeRegionSuboptimalText):
(WebCore::AXMeterGaugeRegionLessGoodText):
(WebCore::builtInPDFPluginName):
(WebCore::pdfDocumentTypeDescription):
(WebCore::postScriptDocumentTypeDescription):
(WebCore::keygenMenuItem2048):
(WebCore::keygenKeychainItemName):
(WebCore::htmlSelectMultipleItems):
(WebCore::fileButtonChooseMediaFileLabel):
(WebCore::fileButtonChooseMultipleMediaFilesLabel):
(WebCore::fileButtonNoMediaFileSelectedLabel):
(WebCore::fileButtonNoMediaFilesSelectedLabel):
(WebCore::insertListTypeNone):
(WebCore::insertListTypeBulleted):
(WebCore::insertListTypeBulletedAccessibilityTitle):
(WebCore::insertListTypeNumbered):
(WebCore::insertListTypeNumberedAccessibilityTitle):
(WebCore::exitFullScreenButtonAccessibilityTitle):
* platform/gtk/LocalizedStringsGtk.cpp:
(WebCore::contextMenuItemTagDelete):
(WebCore::contextMenuItemTagSelectAll):
* platform/win/LocalizedStringsWin.cpp:
(WebCore::contextMenuItemTagSearchWeb):
(WebCore::uploadFileText):
(WebCore::allFilesText):
Source/WebCore/platform/gtk/po:
* CMakeLists.txt: Add keyword parameters for WEB_UI_STRING macros.
* POTFILES.in: Add LocalizedStrings.cpp to the list.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@214244 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/extract-localizable-strings.pl b/Source/WebCore/extract-localizable-strings.pl
index b2c6939..822d293 100755
--- a/Source/WebCore/extract-localizable-strings.pl
+++ b/Source/WebCore/extract-localizable-strings.pl
@@ -132,6 +132,7 @@
my $UIString;
my $key;
my $comment;
+ my $mnemonic;
my $string;
my $stringLine;
@@ -188,6 +189,9 @@
# FIXME: Validate UTF-8 here?
$key = $string;
$expected = ",";
+ } elsif (($macro =~ /WEB_UI_STRING_WITH_MNEMONIC$/) and !defined $mnemonic) {
+ $mnemonic = $string;
+ $expected = ",";
} elsif (!defined $comment) {
# FIXME: Validate UTF-8 here?
$comment = $string;
@@ -240,12 +244,13 @@
emitError($file, $., "found $token but expected $expected");
$expected = "";
}
- if (($token =~ /(WEB_)?UI_STRING(_KEY)?(_INTERNAL)?$/) || ($token =~ /WEB_UI_NSSTRING$/)) {
+ if (($token =~ /(WEB_)?UI_STRING(_KEY)?(_INTERNAL)?$/) || ($token =~ /WEB_UI_NSSTRING$/) || ($token =~ /WEB_UI_STRING_WITH_MNEMONIC$/) || ($token =~ /WEB_UI_CFSTRING$/)) {
$expected = "(";
$macro = $token;
$UIString = undef;
$key = undef;
$comment = undef;
+ $mnemonic = undef;
$macroLine = $.;
} elsif ($token eq "(" or $token eq "[") {
++$nestingLevel if defined $nestingLevel;