1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "config.h"
  27 
  28 #include <wtf/java/JavaEnv.h>
  29 #include "LocalizedStrings.h"
  30 #include "NotImplemented.h"
  31 
  32 #include <wtf/MathExtras.h>
  33 #include <wtf/text/WTFString.h>
  34 
  35 namespace WebCore {
  36 
  37 String getLocalizedProperty(String name)
  38 {
  39     JNIEnv* env = WebCore_GetJavaEnv();
  40 
  41     static JGClass cls(env->FindClass("com/sun/webkit/LocalizedStrings"));
  42     ASSERT(cls);
  43 
  44     static jmethodID mid = env->GetStaticMethodID(cls,
  45         "getLocalizedProperty",
  46         "(Ljava/lang/String;)Ljava/lang/String;");
  47     ASSERT(mid);
  48 
  49 
  50     JLString ls(static_cast<jstring>(env->CallStaticObjectMethod(cls, mid,
  51         (jstring)name.toJavaString(env))));
  52     CheckAndClearException(env);
  53 
  54     return !ls ? name : String(env, ls);
  55 }
  56 
  57 String contextMenuItemTagInspectElement()
  58 {
  59     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagInspectElement");
  60 }
  61 
  62 String inputElementAltText()
  63 {
  64     return getLocalizedProperty("inputElementAltText");
  65 }
  66 
  67 String resetButtonDefaultLabel()
  68 {
  69     return getLocalizedProperty("resetButtonDefaultLabel");
  70 }
  71 
  72 String searchableIndexIntroduction()
  73 {
  74     return getLocalizedProperty("searchableIndexIntroduction");
  75 }
  76 
  77 String submitButtonDefaultLabel()
  78 {
  79     return getLocalizedProperty("submitButtonDefaultLabel");
  80 }
  81 
  82 String fileButtonChooseFileLabel()
  83 {
  84     return getLocalizedProperty("fileButtonChooseFileLabel");
  85 }
  86 
  87 String fileButtonNoFilesSelectedLabel()
  88 {
  89     return getLocalizedProperty("fileButtonNoFilesSelectedLabel");
  90 }
  91 
  92 String fileButtonNoFileSelectedLabel()
  93 {
  94     return getLocalizedProperty("fileButtonNoFileSelectedLabel");
  95 }
  96 
  97 String fileButtonChooseMultipleFilesLabel()
  98 {
  99     return getLocalizedProperty("fileButtonChooseMultipleFilesLabel");
 100 }
 101 
 102 String multipleFileUploadText(unsigned numberOfFiles)
 103 {
 104     return String::number(numberOfFiles) + " " + getLocalizedProperty("multipleFileUploadText");
 105 }
 106 
 107 String contextMenuItemTagOpenLinkInNewWindow()
 108 {
 109     return getLocalizedProperty("contextMenuItemTagOpenLinkInNewWindow");
 110 }
 111 
 112 String contextMenuItemTagDownloadLinkToDisk()
 113 {
 114     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagDownloadLinkToDisk");
 115 }
 116 
 117 String contextMenuItemTagCopyLinkToClipboard()
 118 {
 119     return getLocalizedProperty("contextMenuItemTagCopyLinkToClipboard");
 120 }
 121 
 122 String contextMenuItemTagOpenImageInNewWindow()
 123 {
 124     return getLocalizedProperty("contextMenuItemTagOpenImageInNewWindow");
 125 }
 126 
 127 String contextMenuItemTagDownloadImageToDisk()
 128 {
 129     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagDownloadImageToDisk");
 130 }
 131 
 132 String contextMenuItemTagDownloadAudioToDisk()
 133 {
 134     return String(); // UNSUPPORTED
 135 }
 136 
 137 String contextMenuItemTagDownloadVideoToDisk()
 138 {
 139     return String(); // UNSUPPORTED
 140 }
 141 
 142 String contextMenuItemTagCopyImageToClipboard()
 143 {
 144     return getLocalizedProperty("contextMenuItemTagCopyImageToClipboard");
 145 }
 146 
 147 String contextMenuItemTagOpenFrameInNewWindow()
 148 {
 149     return getLocalizedProperty("contextMenuItemTagOpenFrameInNewWindow");
 150 }
 151 
 152 String contextMenuItemTagCopy()
 153 {
 154     return getLocalizedProperty("contextMenuItemTagCopy");
 155 }
 156 
 157 String contextMenuItemTagGoBack()
 158 {
 159     return getLocalizedProperty("contextMenuItemTagGoBack");
 160 }
 161 
 162 String contextMenuItemTagGoForward()
 163 {
 164     return getLocalizedProperty("contextMenuItemTagGoForward");
 165 }
 166 
 167 String contextMenuItemTagStop()
 168 {
 169     return getLocalizedProperty("contextMenuItemTagStop");
 170 }
 171 
 172 String contextMenuItemTagReload()
 173 {
 174     return getLocalizedProperty("contextMenuItemTagReload");
 175 }
 176 
 177 String contextMenuItemTagCut()
 178 {
 179     return getLocalizedProperty("contextMenuItemTagCut");
 180 }
 181 
 182 String contextMenuItemTagPaste()
 183 {
 184     return getLocalizedProperty("contextMenuItemTagPaste");
 185 }
 186 
 187 String contextMenuItemTagNoGuessesFound()
 188 {
 189     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagNoGuessesFound");
 190 }
 191 
 192 String contextMenuItemTagIgnoreSpelling()
 193 {
 194     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagIgnoreSpelling");
 195 }
 196 
 197 String contextMenuItemTagLearnSpelling()
 198 {
 199     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagLearnSpelling");
 200 }
 201 
 202 String contextMenuItemTagSearchWeb()
 203 {
 204     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagSearchWeb");
 205 }
 206 
 207 String contextMenuItemTagLookUpInDictionary()
 208 {
 209     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagLookUpInDictionary");
 210 }
 211 
 212 String contextMenuItemTagOpenLink()
 213 {
 214     return getLocalizedProperty("contextMenuItemTagOpenLink");
 215 }
 216 
 217 String contextMenuItemTagIgnoreGrammar()
 218 {
 219     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagIgnoreGrammar");
 220 }
 221 
 222 String contextMenuItemTagSpellingMenu()
 223 {
 224     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagSpellingMenu");
 225 }
 226 
 227 String contextMenuItemTagShowSpellingPanel(bool)
 228 {
 229     return String(); /* UNSUPPORTED: show
 230             ? getLocalizedProperty("contextMenuItemTagShowSpellingPanelShow")
 231             : getLocalizedProperty("contextMenuItemTagShowSpellingPanelHide");*/
 232 }
 233 
 234 String contextMenuItemTagCheckSpelling()
 235 {
 236     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagCheckSpelling");
 237 }
 238 
 239 String contextMenuItemTagCheckSpellingWhileTyping()
 240 {
 241     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagCheckSpellingWhileTyping");
 242 }
 243 
 244 String contextMenuItemTagCheckGrammarWithSpelling()
 245 {
 246     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagCheckGrammarWithSpelling");
 247 }
 248 
 249 String contextMenuItemTagFontMenu()
 250 {
 251     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagFontMenu");
 252 }
 253 
 254 String contextMenuItemTagBold()
 255 {
 256     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagBold");
 257 }
 258 
 259 String contextMenuItemTagItalic()
 260 {
 261     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagItalic");
 262 }
 263 
 264 String contextMenuItemTagUnderline()
 265 {
 266     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagUnderline");
 267 }
 268 
 269 String contextMenuItemTagOutline()
 270 {
 271     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagOutline");
 272 }
 273 
 274 String contextMenuItemTagWritingDirectionMenu()
 275 {
 276     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagWritingDirectionMenu");
 277 }
 278 
 279 String contextMenuItemTagDefaultDirection()
 280 {
 281     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagDefaultDirection");
 282 }
 283 
 284 String contextMenuItemTagLeftToRight()
 285 {
 286     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagLeftToRight");
 287 }
 288 
 289 String contextMenuItemTagRightToLeft()
 290 {
 291     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagRightToLeft");
 292 }
 293 
 294 String contextMenuItemTagTextDirectionMenu()
 295 {
 296     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagTextDirectionMenu");
 297 }
 298 
 299 String searchMenuNoRecentSearchesText()
 300 {
 301     return getLocalizedProperty("searchMenuNoRecentSearchesText");
 302 }
 303 
 304 String searchMenuRecentSearchesText()
 305 {
 306     return getLocalizedProperty("searchMenuRecentSearchesText");
 307 }
 308 
 309 String searchMenuClearRecentSearchesText()
 310 {
 311     return getLocalizedProperty("searchMenuClearRecentSearchesText");
 312 }
 313 
 314 String unknownFileSizeText()
 315 {
 316     return getLocalizedProperty("unknownFileSizeText");
 317 }
 318 
 319 String crashedPluginText()
 320 {
 321     return getLocalizedProperty("crashedPluginText");
 322 }
 323 
 324 String blockedPluginByContentSecurityPolicyText()
 325 {
 326     return getLocalizedProperty("blockedPluginByContentSecurityPolicyText");
 327 }
 328 
 329 String inactivePluginText()
 330 {
 331     return getLocalizedProperty("inactivePluginText");
 332 }
 333 
 334 String snapshottedPlugInLabelSubtitle()
 335 {
 336     return getLocalizedProperty("snapshottedPlugInLabelSubtitle");
 337 }
 338 
 339 String snapshottedPlugInLabelTitle()
 340 {
 341     return getLocalizedProperty("snapshottedPlugInLabelTitle");
 342 }
 343 
 344 String missingPluginText()
 345 {
 346     return getLocalizedProperty("missingPluginText");
 347 }
 348 
 349 String insecurePluginVersionText()
 350 {
 351     return getLocalizedProperty("insecurePluginVersionText");
 352 }
 353 
 354 
 355 String imageTitle(const String&, const IntSize&)
 356 {
 357     return String();
 358 }
 359 
 360 String contextMenuItemTagCopyAudioLinkToClipboard()
 361 {
 362     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagCopyAudioLinkToClipboard");
 363 }
 364 
 365 String contextMenuItemTagCopyVideoLinkToClipboard()
 366 {
 367     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagCopyVideoLinkToClipboard");
 368 }
 369 
 370 String contextMenuItemTagEnterVideoFullscreen()
 371 {
 372     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagEnterVideoFullscreen");
 373 }
 374 
 375 #if ENABLE(VIDEO_TRACK)
 376 String textTrackSubtitlesText()
 377 {
 378     return String::fromUTF8("Subtitles");
 379 }
 380 
 381 String textTrackOffMenuItemText()
 382 {
 383     return String::fromUTF8("Off");
 384 }
 385 
 386 String textTrackAutomaticMenuItemText()
 387 {
 388     return String::fromUTF8("Auto");
 389 }
 390 
 391 String textTrackNoLabelText()
 392 {
 393     return String::fromUTF8("No label");
 394 }
 395 
 396 String audioTrackNoLabelText()
 397 {
 398     return String::fromUTF8("No label");
 399 }
 400 #endif
 401 
 402 String contextMenuItemTagMediaPlay()
 403 {
 404     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagMediaPlay");
 405 }
 406 
 407 String contextMenuItemTagMediaPause()
 408 {
 409     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagMediaPause");
 410 }
 411 
 412 String contextMenuItemTagMediaMute()
 413 {
 414     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagMediaMute");
 415 }
 416 
 417 String contextMenuItemTagOpenAudioInNewWindow()
 418 {
 419     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagOpenAudioInNewWindow");
 420 }
 421 
 422 String contextMenuItemTagOpenVideoInNewWindow()
 423 {
 424     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagOpenVideoInNewWindow");
 425 }
 426 
 427 String contextMenuItemTagToggleMediaControls()
 428 {
 429     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagToggleMediaControls");
 430 }
 431 
 432 String contextMenuItemTagToggleMediaLoop()
 433 {
 434     return String(); // UNSUPPORTED: getLocalizedProperty("contextMenuItemTagToggleMediaLoop");
 435 }
 436 
 437 String mediaElementLoadingStateText()
 438 {
 439     return getLocalizedProperty("mediaElementLoadingStateText");
 440 }
 441 
 442 String mediaElementLiveBroadcastStateText()
 443 {
 444     return getLocalizedProperty("mediaElementLiveBroadcastStateText");
 445 }
 446 
 447 String localizedMediaControlElementString(const String& s)
 448 {
 449     return getLocalizedProperty(String("localizedMediaControlElementString") + s);
 450 }
 451 
 452 String localizedMediaControlElementHelpText(const String& s)
 453 {
 454     return getLocalizedProperty(String("localizedMediaControlElementHelpText") + s);
 455 }
 456 
 457 String localizedMediaTimeDescription(float time)
 458 {
 459     if (!std::isfinite(time))
 460         return getLocalizedProperty("localizedMediaTimeDescriptionIndefinite");
 461 
 462     int seconds = (int)fabsf(time);
 463     int days = seconds / (60 * 60 * 24);
 464     int hours = seconds / (60 * 60);
 465     int minutes = (seconds / 60) % 60;
 466     seconds %= 60;
 467 
 468     String result;
 469     if (days) {
 470         String s = getLocalizedProperty("localizedMediaTimeDescriptionDays");
 471         result.append(String::number(days) + " " + s + "  ");
 472     }
 473     if (days || hours) {
 474         String s = getLocalizedProperty("localizedMediaTimeDescriptionHours");
 475         result.append(String::number(hours) + " " + s + "  ");
 476     }
 477     if (days || hours || minutes) {
 478         String s = getLocalizedProperty("localizedMediaTimeDescriptionMinutes");
 479         result.append(String::number(minutes) + " " + s + "  ");
 480     }
 481     String s = getLocalizedProperty("localizedMediaTimeDescriptionSeconds");
 482     return result + String::number(days) + " " + s;
 483 }
 484 
 485 String AXWebAreaText()
 486 {
 487     return getLocalizedProperty("AXWebAreaText");
 488 }
 489 
 490 String AXLinkText()
 491 {
 492     return getLocalizedProperty("AXLinkText");
 493 }
 494 
 495 String AXListMarkerText()
 496 {
 497     return getLocalizedProperty("AXListMarkerText");
 498 }
 499 
 500 String AXImageMapText()
 501 {
 502     return getLocalizedProperty("AXImageMapText");
 503 }
 504 
 505 String AXHeadingText()
 506 {
 507     return getLocalizedProperty("AXHeadingText");
 508 }
 509 
 510 String AXDefinitionListTermText()
 511 {
 512     return getLocalizedProperty("AXDefinitionListTermText");
 513 }
 514 
 515 String AXDefinitionListDefinitionText()
 516 {
 517     return getLocalizedProperty("AXDefinitionListDefinitionText");
 518 }
 519 
 520 String AXButtonActionVerb()
 521 {
 522     return getLocalizedProperty("AXButtonActionVerb");
 523 }
 524 
 525 String AXRadioButtonActionVerb()
 526 {
 527     return getLocalizedProperty("AXRadioButtonActionVerb");
 528 }
 529 
 530 String AXTextFieldActionVerb()
 531 {
 532     return getLocalizedProperty("AXTextFieldActionVerb");
 533 }
 534 
 535 String AXCheckedCheckBoxActionVerb()
 536 {
 537     return getLocalizedProperty("AXCheckedCheckBoxActionVerb");
 538 }
 539 
 540 String AXUncheckedCheckBoxActionVerb()
 541 {
 542     return getLocalizedProperty("AXUncheckedCheckBoxActionVerb");
 543 }
 544 
 545 String AXLinkActionVerb()
 546 {
 547     return getLocalizedProperty("AXLinkActionVerb");
 548 }
 549 
 550 String AXMenuListPopupActionVerb()
 551 {
 552     return getLocalizedProperty("AXMenuListPopupActionVerb");
 553 }
 554 
 555 String AXMenuListActionVerb()
 556 {
 557     return getLocalizedProperty("AXMenuListActionVerb");
 558 }
 559 
 560 String AXSearchFieldCancelButtonText() {
 561     notImplemented();
 562     return String(); // UNSUPPORTED: getLocalizedProperty("AXSearchFieldCancelButtonText");
 563 }
 564 
 565 String AXAutoFillStrongPasswordLabel()
 566 {
 567     // return WEB_UI_STRING("strong password auto fill", "Label for the strong password auto fill button inside a text field.");
 568     return getLocalizedProperty("AXAutoFillStrongPasswordLabel");
 569 }
 570 
 571 String AXAutoFillStrongConfirmationPasswordLabel()
 572 {
 573     // return WEB_UI_STRING("strong confirmation password auto fill", "Label for the strong confirmation password auto fill button inside a text field.");
 574     return getLocalizedProperty("AXAutoFillStrongConfirmationPasswordLabel");
 575 }
 576 
 577 String autoFillStrongPasswordLabel()
 578 {
 579     // return WEB_UI_STRING("strong password", "Label for strong password.");
 580     return getLocalizedProperty("autoFillStrongPasswordLabel");
 581 }
 582 
 583 String validationMessageValueMissingText()
 584 {
 585     return getLocalizedProperty("validationMessageValueMissingText");
 586 }
 587 
 588 String validationMessageTypeMismatchText()
 589 {
 590     return getLocalizedProperty("validationMessageTypeMismatchText");
 591 }
 592 
 593 String validationMessagePatternMismatchText()
 594 {
 595     return getLocalizedProperty("validationMessagePatternMismatchText");
 596 }
 597 
 598 String validationMessageTooShortText(int, int)
 599 {
 600     notImplemented();
 601     return String::fromUTF8("too short");
 602 }
 603 
 604 String validationMessageTooLongText(int, int)
 605 {
 606     return getLocalizedProperty("validationMessageTooLongText");
 607 }
 608 
 609 String validationMessageRangeUnderflowText(const String&)
 610 {
 611     return getLocalizedProperty("validationMessageRangeUnderflowText");
 612 }
 613 
 614 String validationMessageRangeOverflowText(const String&)
 615 {
 616     return getLocalizedProperty("validationMessageRangeOverflowText");
 617 }
 618 
 619 String validationMessageStepMismatchText(const String&, const String&)
 620 {
 621     return getLocalizedProperty("validationMessageStepMismatchText");
 622 }
 623 
 624 String validationMessageTypeMismatchForEmailText()
 625 {
 626     notImplemented();
 627     return validationMessageTypeMismatchText();
 628 }
 629 
 630 String validationMessageTypeMismatchForMultipleEmailText()
 631 {
 632     notImplemented();
 633     return validationMessageTypeMismatchText();
 634 }
 635 
 636 String validationMessageTypeMismatchForURLText()
 637 {
 638     notImplemented();
 639     return validationMessageTypeMismatchText();
 640 }
 641 
 642 String validationMessageValueMissingForCheckboxText()
 643 {
 644     notImplemented();
 645     return validationMessageValueMissingText();
 646 }
 647 
 648 String validationMessageValueMissingForFileText()
 649 {
 650     notImplemented();
 651     return validationMessageValueMissingText();
 652 }
 653 
 654 String validationMessageValueMissingForMultipleFileText()
 655 {
 656     notImplemented();
 657     return validationMessageValueMissingText();
 658 }
 659 
 660 String validationMessageValueMissingForRadioText()
 661 {
 662     notImplemented();
 663     return validationMessageValueMissingText();
 664 }
 665 
 666 String validationMessageValueMissingForSelectText()
 667 {
 668     notImplemented();
 669     return validationMessageValueMissingText();
 670 }
 671 
 672 String validationMessageBadInputForNumberText()
 673 {
 674     return getLocalizedProperty("validationMessageBadInputForNumberText");
 675 }
 676 
 677 #if ENABLE(INPUT_TYPE_WEEK)
 678 // weekFormatInLDML() returns week and year format in LDML, Unicode
 679 // technical standard 35, Locale Data Markup Language, e.g. "'Week' ww, yyyy"
 680 String weekFormatInLDML()
 681 {
 682     return getLocalizedProperty("weekFormatInLDML");
 683 }
 684 #endif
 685 
 686 
 687 String defaultDetailsSummaryText()
 688 {
 689     return getLocalizedProperty("defaultDetailsSummaryText");
 690 }
 691 
 692 String AXAutoFillCredentialsLabel()
 693 {
 694     notImplemented();
 695     return String::fromUTF8("password auto fill");
 696 }
 697 
 698 String AXAutoFillContactsLabel()
 699 {
 700     notImplemented();
 701     return String::fromUTF8("contact info auto fill");
 702 }
 703 
 704 } // namespace WebCore