Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2009 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include "config.h"
     32 #include "core/platform/LocalizedStrings.h"
     33 
     34 #include "core/platform/NotImplemented.h"
     35 #include "core/platform/graphics/IntSize.h"
     36 #include "core/platform/text/DateTimeFormat.h"
     37 
     38 #include "public/platform/Platform.h"
     39 #include "public/platform/WebLocalizedString.h"
     40 #include "public/platform/WebString.h"
     41 #include "wtf/text/StringBuilder.h"
     42 #include "wtf/text/WTFString.h"
     43 
     44 using WebKit::WebLocalizedString;
     45 using WebKit::WebString;
     46 
     47 namespace WebCore {
     48 
     49 static String query(WebLocalizedString::Name name)
     50 {
     51     return WebKit::Platform::current()->queryLocalizedString(name);
     52 }
     53 
     54 static String query(WebLocalizedString::Name name, const WebString& parameter)
     55 {
     56     return WebKit::Platform::current()->queryLocalizedString(name, parameter);
     57 }
     58 
     59 static String query(WebLocalizedString::Name name, const WebString& parameter1, const WebString& parameter2)
     60 {
     61     return WebKit::Platform::current()->queryLocalizedString(name, parameter1, parameter2);
     62 }
     63 
     64 String searchableIndexIntroduction()
     65 {
     66     return query(WebLocalizedString::SearchableIndexIntroduction);
     67 }
     68 
     69 String submitButtonDefaultLabel()
     70 {
     71     return query(WebLocalizedString::SubmitButtonDefaultLabel);
     72 }
     73 
     74 String inputElementAltText()
     75 {
     76     return query(WebLocalizedString::InputElementAltText);
     77 }
     78 
     79 String resetButtonDefaultLabel()
     80 {
     81     return query(WebLocalizedString::ResetButtonDefaultLabel);
     82 }
     83 
     84 String fileButtonChooseFileLabel()
     85 {
     86     return query(WebLocalizedString::FileButtonChooseFileLabel);
     87 }
     88 
     89 String fileButtonChooseMultipleFilesLabel()
     90 {
     91     return query(WebLocalizedString::FileButtonChooseMultipleFilesLabel);
     92 }
     93 
     94 String defaultDetailsSummaryText()
     95 {
     96     return query(WebLocalizedString::DetailsLabel);
     97 }
     98 
     99 String fileButtonNoFileSelectedLabel()
    100 {
    101     return query(WebLocalizedString::FileButtonNoFileSelectedLabel);
    102 }
    103 
    104 String fileButtonNoFilesSelectedLabel()
    105 {
    106     return query(WebLocalizedString::FileButtonNoFileSelectedLabel);
    107 }
    108 
    109 String searchMenuNoRecentSearchesText()
    110 {
    111     return query(WebLocalizedString::SearchMenuNoRecentSearchesText);
    112 }
    113 String searchMenuRecentSearchesText()
    114 {
    115     return query(WebLocalizedString::SearchMenuRecentSearchesText);
    116 }
    117 
    118 String searchMenuClearRecentSearchesText()
    119 {
    120     return query(WebLocalizedString::SearchMenuClearRecentSearchesText);
    121 }
    122 
    123 String AXWebAreaText()
    124 {
    125     return query(WebLocalizedString::AXWebAreaText);
    126 }
    127 
    128 String AXLinkText()
    129 {
    130     return query(WebLocalizedString::AXLinkText);
    131 }
    132 
    133 String AXListMarkerText()
    134 {
    135     return query(WebLocalizedString::AXListMarkerText);
    136 }
    137 
    138 String AXImageMapText()
    139 {
    140     return query(WebLocalizedString::AXImageMapText);
    141 }
    142 
    143 String AXHeadingText()
    144 {
    145     return query(WebLocalizedString::AXHeadingText);
    146 }
    147 
    148 String AXButtonActionVerb()
    149 {
    150     return query(WebLocalizedString::AXButtonActionVerb);
    151 }
    152 
    153 String AXRadioButtonActionVerb()
    154 {
    155     return query(WebLocalizedString::AXRadioButtonActionVerb);
    156 }
    157 
    158 String AXTextFieldActionVerb()
    159 {
    160     return query(WebLocalizedString::AXTextFieldActionVerb);
    161 }
    162 
    163 String AXCheckedCheckBoxActionVerb()
    164 {
    165     return query(WebLocalizedString::AXCheckedCheckBoxActionVerb);
    166 }
    167 
    168 String AXUncheckedCheckBoxActionVerb()
    169 {
    170     return query(WebLocalizedString::AXUncheckedCheckBoxActionVerb);
    171 }
    172 
    173 String AXLinkActionVerb()
    174 {
    175     return query(WebLocalizedString::AXLinkActionVerb);
    176 }
    177 
    178 String AXMenuListPopupActionVerb()
    179 {
    180     return String();
    181 }
    182 
    183 String AXMenuListActionVerb()
    184 {
    185     return String();
    186 }
    187 
    188 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    189 String AXAMPMFieldText()
    190 {
    191     return query(WebLocalizedString::AXAMPMFieldText);
    192 }
    193 
    194 String AXDayOfMonthFieldText()
    195 {
    196     return query(WebLocalizedString::AXDayOfMonthFieldText);
    197 }
    198 
    199 String AXDateTimeFieldEmptyValueText()
    200 {
    201     return query(WebLocalizedString::AXDateTimeFieldEmptyValueText);
    202 }
    203 
    204 String AXHourFieldText()
    205 {
    206     return query(WebLocalizedString::AXHourFieldText);
    207 }
    208 
    209 String AXMillisecondFieldText()
    210 {
    211     return query(WebLocalizedString::AXMillisecondFieldText);
    212 }
    213 
    214 String AXMinuteFieldText()
    215 {
    216     return query(WebLocalizedString::AXMinuteFieldText);
    217 }
    218 
    219 String AXMonthFieldText()
    220 {
    221     return query(WebLocalizedString::AXMonthFieldText);
    222 }
    223 
    224 String AXSecondFieldText()
    225 {
    226     return query(WebLocalizedString::AXSecondFieldText);
    227 }
    228 
    229 String AXWeekOfYearFieldText()
    230 {
    231     return query(WebLocalizedString::AXWeekOfYearFieldText);
    232 }
    233 
    234 String AXYearFieldText()
    235 {
    236     return query(WebLocalizedString::AXYearFieldText);
    237 }
    238 
    239 String placeholderForDayOfMonthField()
    240 {
    241     return query(WebLocalizedString::PlaceholderForDayOfMonthField);
    242 }
    243 
    244 String placeholderForMonthField()
    245 {
    246     return query(WebLocalizedString::PlaceholderForMonthField);
    247 }
    248 
    249 String placeholderForYearField()
    250 {
    251     return query(WebLocalizedString::PlaceholderForYearField);
    252 }
    253 #endif
    254 
    255 String weekFormatInLDML()
    256 {
    257     String templ = query(WebLocalizedString::WeekFormatTemplate);
    258     // Converts a string like "Week $2, $1" to an LDML date format pattern like
    259     // "'Week 'ww', 'yyyy".
    260     StringBuilder builder;
    261     unsigned literalStart = 0;
    262     unsigned length = templ.length();
    263     for (unsigned i = 0; i + 1 < length; ++i) {
    264         if (templ[i] == '$' && (templ[i + 1] == '1' || templ[i + 1] == '2')) {
    265             if (literalStart < i)
    266                 DateTimeFormat::quoteAndAppendLiteral(templ.substring(literalStart, i - literalStart), builder);
    267             builder.append(templ[++i] == '1' ? "yyyy" : "ww");
    268             literalStart = i + 1;
    269         }
    270     }
    271     if (literalStart < length)
    272         DateTimeFormat::quoteAndAppendLiteral(templ.substring(literalStart, length - literalStart), builder);
    273     return builder.toString();
    274 }
    275 
    276 String missingPluginText()
    277 {
    278     return query(WebLocalizedString::MissingPluginText);
    279 }
    280 
    281 String blockedPluginByContentSecurityPolicyText()
    282 {
    283     notImplemented();
    284     return String();
    285 }
    286 
    287 String multipleFileUploadText(unsigned numberOfFiles)
    288 {
    289     return query(WebLocalizedString::MultipleFileUploadText, String::number(numberOfFiles));
    290 }
    291 
    292 // The following two functions are not declared in core/platform/LocalizedStrings.h.
    293 // They are used by the menu for the HTML keygen tag.
    294 String keygenMenuHighGradeKeySize()
    295 {
    296     return query(WebLocalizedString::KeygenMenuHighGradeKeySize);
    297 }
    298 
    299 String keygenMenuMediumGradeKeySize()
    300 {
    301     return query(WebLocalizedString::KeygenMenuMediumGradeKeySize);
    302 }
    303 
    304 // Used in ImageDocument.cpp as the title for pages when that page is an image.
    305 String imageTitle(const String& filename, const IntSize& size)
    306 {
    307     StringBuilder result;
    308     result.append(filename);
    309     result.append(" (");
    310     result.append(String::number(size.width()));
    311     result.append(static_cast<UChar>(0xD7)); // U+00D7 (multiplication sign)
    312     result.append(String::number(size.height()));
    313     result.append(')');
    314     return result.toString();
    315 }
    316 
    317 String textTrackClosedCaptionsText() { return String(); }
    318 String textTrackSubtitlesText() { return String(); }
    319 String textTrackOffText() { return String(); }
    320 String textTrackNoLabelText() { return String(); }
    321 
    322 String localizedMediaControlElementString(const String& name)
    323 {
    324     if (name == "AudioElement")
    325         return query(WebLocalizedString::AXMediaAudioElement);
    326     if (name == "VideoElement")
    327         return query(WebLocalizedString::AXMediaVideoElement);
    328     if (name == "MuteButton")
    329         return query(WebLocalizedString::AXMediaMuteButton);
    330     if (name == "UnMuteButton")
    331         return query(WebLocalizedString::AXMediaUnMuteButton);
    332     if (name == "PlayButton")
    333         return query(WebLocalizedString::AXMediaPlayButton);
    334     if (name == "PauseButton")
    335         return query(WebLocalizedString::AXMediaPauseButton);
    336     if (name == "Slider")
    337         return query(WebLocalizedString::AXMediaSlider);
    338     if (name == "SliderThumb")
    339         return query(WebLocalizedString::AXMediaSliderThumb);
    340     if (name == "RewindButton")
    341         return query(WebLocalizedString::AXMediaRewindButton);
    342     if (name == "ReturnToRealtimeButton")
    343         return query(WebLocalizedString::AXMediaReturnToRealTime);
    344     if (name == "CurrentTimeDisplay")
    345         return query(WebLocalizedString::AXMediaCurrentTimeDisplay);
    346     if (name == "TimeRemainingDisplay")
    347         return query(WebLocalizedString::AXMediaTimeRemainingDisplay);
    348     if (name == "StatusDisplay")
    349         return query(WebLocalizedString::AXMediaStatusDisplay);
    350     if (name == "EnterFullscreenButton")
    351         return query(WebLocalizedString::AXMediaEnterFullscreenButton);
    352     if (name == "ExitFullscreenButton")
    353         return query(WebLocalizedString::AXMediaExitFullscreenButton);
    354     if (name == "SeekForwardButton")
    355         return query(WebLocalizedString::AXMediaSeekForwardButton);
    356     if (name == "SeekBackButton")
    357         return query(WebLocalizedString::AXMediaSeekBackButton);
    358     if (name == "ShowClosedCaptionsButton")
    359         return query(WebLocalizedString::AXMediaShowClosedCaptionsButton);
    360     if (name == "HideClosedCaptionsButton")
    361         return query(WebLocalizedString::AXMediaHideClosedCaptionsButton);
    362 
    363     // FIXME: the ControlsPanel container should never be visible in the accessibility hierarchy.
    364     if (name == "ControlsPanel")
    365         return query(WebLocalizedString::AXMediaDefault);
    366 
    367     ASSERT_NOT_REACHED();
    368     return query(WebLocalizedString::AXMediaDefault);
    369 }
    370 
    371 String localizedMediaControlElementHelpText(const String& name)
    372 {
    373     if (name == "AudioElement")
    374         return query(WebLocalizedString::AXMediaAudioElementHelp);
    375     if (name == "VideoElement")
    376         return query(WebLocalizedString::AXMediaVideoElementHelp);
    377     if (name == "MuteButton")
    378         return query(WebLocalizedString::AXMediaMuteButtonHelp);
    379     if (name == "UnMuteButton")
    380         return query(WebLocalizedString::AXMediaUnMuteButtonHelp);
    381     if (name == "PlayButton")
    382         return query(WebLocalizedString::AXMediaPlayButtonHelp);
    383     if (name == "PauseButton")
    384         return query(WebLocalizedString::AXMediaPauseButtonHelp);
    385     if (name == "Slider")
    386         return query(WebLocalizedString::AXMediaSliderHelp);
    387     if (name == "SliderThumb")
    388         return query(WebLocalizedString::AXMediaSliderThumbHelp);
    389     if (name == "RewindButton")
    390         return query(WebLocalizedString::AXMediaRewindButtonHelp);
    391     if (name == "ReturnToRealtimeButton")
    392         return query(WebLocalizedString::AXMediaReturnToRealTimeHelp);
    393     if (name == "CurrentTimeDisplay")
    394         return query(WebLocalizedString::AXMediaCurrentTimeDisplayHelp);
    395     if (name == "TimeRemainingDisplay")
    396         return query(WebLocalizedString::AXMediaTimeRemainingDisplayHelp);
    397     if (name == "StatusDisplay")
    398         return query(WebLocalizedString::AXMediaStatusDisplayHelp);
    399     if (name == "EnterFullscreenButton")
    400         return query(WebLocalizedString::AXMediaEnterFullscreenButtonHelp);
    401     if (name == "ExitFullscreenButton")
    402         return query(WebLocalizedString::AXMediaExitFullscreenButtonHelp);
    403     if (name == "SeekForwardButton")
    404         return query(WebLocalizedString::AXMediaSeekForwardButtonHelp);
    405     if (name == "SeekBackButton")
    406         return query(WebLocalizedString::AXMediaSeekBackButtonHelp);
    407     if (name == "ShowClosedCaptionsButton")
    408         return query(WebLocalizedString::AXMediaShowClosedCaptionsButtonHelp);
    409     if (name == "HideClosedCaptionsButton")
    410         return query(WebLocalizedString::AXMediaHideClosedCaptionsButtonHelp);
    411 
    412     ASSERT_NOT_REACHED();
    413     return query(WebLocalizedString::AXMediaDefault);
    414 }
    415 
    416 String localizedMediaTimeDescription(float /*time*/)
    417 {
    418     // FIXME: to be fixed.
    419     return String();
    420 }
    421 
    422 String validationMessageValueMissingText()
    423 {
    424     return query(WebLocalizedString::ValidationValueMissing);
    425 }
    426 
    427 String validationMessageValueMissingForCheckboxText()
    428 {
    429     return query(WebLocalizedString::ValidationValueMissingForCheckbox);
    430 }
    431 
    432 String validationMessageValueMissingForFileText()
    433 {
    434     return query(WebLocalizedString::ValidationValueMissingForFile);
    435 }
    436 
    437 String validationMessageValueMissingForMultipleFileText()
    438 {
    439     return query(WebLocalizedString::ValidationValueMissingForMultipleFile);
    440 }
    441 
    442 String validationMessageValueMissingForRadioText()
    443 {
    444     return query(WebLocalizedString::ValidationValueMissingForRadio);
    445 }
    446 
    447 String validationMessageValueMissingForSelectText()
    448 {
    449     return query(WebLocalizedString::ValidationValueMissingForSelect);
    450 }
    451 
    452 String validationMessageTypeMismatchText()
    453 {
    454     return query(WebLocalizedString::ValidationTypeMismatch);
    455 }
    456 
    457 String validationMessageTypeMismatchForEmailText()
    458 {
    459     return query(WebLocalizedString::ValidationTypeMismatchForEmail);
    460 }
    461 
    462 String validationMessageTypeMismatchForMultipleEmailText()
    463 {
    464     return query(WebLocalizedString::ValidationTypeMismatchForMultipleEmail);
    465 }
    466 
    467 String validationMessageTypeMismatchForURLText()
    468 {
    469     return query(WebLocalizedString::ValidationTypeMismatchForURL);
    470 }
    471 
    472 String validationMessagePatternMismatchText()
    473 {
    474     return query(WebLocalizedString::ValidationPatternMismatch);
    475 }
    476 
    477 String validationMessageTooLongText(int valueLength, int maxLength)
    478 {
    479     return query(WebLocalizedString::ValidationTooLong, String::number(valueLength), String::number(maxLength));
    480 }
    481 
    482 String validationMessageRangeUnderflowText(const String& minimum)
    483 {
    484     return query(WebLocalizedString::ValidationRangeUnderflow, minimum);
    485 }
    486 
    487 String validationMessageRangeOverflowText(const String& maximum)
    488 {
    489     return query(WebLocalizedString::ValidationRangeOverflow, maximum);
    490 }
    491 
    492 String validationMessageStepMismatchText(const String& base, const String& step)
    493 {
    494     return query(WebLocalizedString::ValidationStepMismatch, base, step);
    495 }
    496 
    497 String validationMessageBadInputForNumberText()
    498 {
    499     return query(WebLocalizedString::ValidationBadInputForNumber);
    500 }
    501 
    502 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
    503 String validationMessageBadInputForDateTimeText()
    504 {
    505     return query(WebLocalizedString::ValidationBadInputForDateTime);
    506 }
    507 #endif
    508 
    509 } // namespace WebCore
    510