/*
 * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
 * Copyright (C) 2007 Holger Hans Peter Freyther
 * Copyright (C) 2008 Christian Dywan <christian@imendio.com>
 * Copyright (C) 2008 Nuanti Ltd.
 * Copyright (C) 2009, 2010, 2011 Espial Group Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "config.h"
#include "LocalizedStrings.h"
#include "NotImplemented.h"
#include "PlatformString.h"
#include <math.h>
#include <stdio.h>

namespace WebCore {

String submitButtonDefaultLabel()
{
    return String("Submit", String::ConstructFromLiteral);
}

String inputElementAltText()
{
    return String("Submit", String::ConstructFromLiteral);
}

String resetButtonDefaultLabel()
{
    return String("Reset", String::ConstructFromLiteral);
}

String searchableIndexIntroduction()
{
    return String("_Searchable Index", String::ConstructFromLiteral);
}

String fileButtonChooseFileLabel()
{
    return String("Choose File", String::ConstructFromLiteral);
}

String fileButtonChooseMultipleFilesLabel()
{
    return String("Choose Files", String::ConstructFromLiteral);
}

String fileButtonNoFileSelectedLabel()
{
    return String("(None)", String::ConstructFromLiteral);
}

String fileButtonNoFilesSelectedLabel()
{
    return String("(None)", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenLinkInNewWindow()
{
    return String("Open Link in New _Window", String::ConstructFromLiteral);
}

String contextMenuItemTagDownloadLinkToDisk()
{
    return String("_Download Linked File", String::ConstructFromLiteral);
}

String contextMenuItemTagCopyLinkToClipboard()
{
    return String("Copy Link Loc_ation", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenImageInNewWindow()
{
    return String("Open _Image in New Window", String::ConstructFromLiteral);
}

String contextMenuItemTagDownloadImageToDisk()
{
    return String("Sa_ve Image As", String::ConstructFromLiteral);
}

String contextMenuItemTagCopyImageToClipboard()
{
    return String("Cop_y Image", String::ConstructFromLiteral);
}

String contextMenuItemTagCopyImageUrlToClipboard()
{
    return String("Copy Image _Address", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenFrameInNewWindow()
{
    return String("Open _Frame in New Window", String::ConstructFromLiteral);
}

String contextMenuItemTagMediaPlay()
{
    return String("_Play", String::ConstructFromLiteral);
}

String contextMenuItemTagMediaPause()
{
    return String("_Pause", String::ConstructFromLiteral);
}

String contextMenuItemTagMediaMute()
{
    return String("_Mute", String::ConstructFromLiteral);
}

String contextMenuItemTagToggleMediaControls()
{
    return String("_Toggle Media Controls", String::ConstructFromLiteral);
}

String contextMenuItemTagToggleMediaLoop()
{
    return String("Toggle Media _Loop Playback", String::ConstructFromLiteral);
}

String contextMenuItemTagEnterVideoFullscreen()
{
    return String("Switch Video to _Fullscreen", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenVideoInNewWindow()
{
    return String("Open _Video in New Window", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenAudioInNewWindow()
{
    return String("Open _Audio in New Window", String::ConstructFromLiteral);
}

String contextMenuItemTagCopyVideoLinkToClipboard()
{
    return String("Cop_y Video Link Location", String::ConstructFromLiteral);
}

String contextMenuItemTagCopyAudioLinkToClipboard()
{
    return String("Cop_y Audio Link Location", String::ConstructFromLiteral);
}

String contextMenuItemTagCopy()
{
    return String("Tag Copy", String::ConstructFromLiteral);
}

String contextMenuItemTagDelete()
{
	return String("Tag Delete", String::ConstructFromLiteral);
}

String contextMenuItemTagSelectAll()
{	
	return String("Select _All", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicode()
{
    return String("_Insert Unicode Control Character", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertLRMMark()
{
    return String("LRM _Left-to-right mark", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertRLMMark()
{
    return String("RLM _Right-to-left mark", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertLREMark()
{
    return String("LRE Left-to-right _embedding", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertRLEMark()
{
    return String("RLE Right-to-left e_mbedding", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertLROMark()
{
    return String("LRO Left-to-right _override", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertRLOMark()
{
    return String("RLO Right-to-left o_verride", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertPDFMark()
{
    return String("PDF _Pop directional formatting", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertZWSMark()
{
    return String("ZWS _Zero width space", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertZWJMark()
{
    return String("ZWJ Zero width _joiner", String::ConstructFromLiteral);
}

String contextMenuItemTagUnicodeInsertZWNJMark()
{
    return String("ZWNJ Zero width _non-joiner", String::ConstructFromLiteral);
}

String contextMenuItemTagInputMethods()
{
    return String("Input _Methods", String::ConstructFromLiteral);
}

String contextMenuItemTagGoBack()
{
	return String("Tag Go Back", String::ConstructFromLiteral);
}

String contextMenuItemTagGoForward()
{
	return String("Tag Go Forward", String::ConstructFromLiteral);
}

String contextMenuItemTagStop()
{
	return String("Tag Stop", String::ConstructFromLiteral);
}

String contextMenuItemTagReload()
{
    return String("_Reload", String::ConstructFromLiteral);
}

String contextMenuItemTagCut()
{
	return String("Tag Cut", String::ConstructFromLiteral);
}

String contextMenuItemTagPaste()
{
	return String("Tag Paste", String::ConstructFromLiteral);
}

String contextMenuItemTagNoGuessesFound()
{
    return String("No Guesses Found", String::ConstructFromLiteral);
}

String contextMenuItemTagIgnoreSpelling()
{
    return String("_Ignore Spelling", String::ConstructFromLiteral);
}

String contextMenuItemTagLearnSpelling()
{
    return String("_Learn Spelling", String::ConstructFromLiteral);
}

String contextMenuItemTagSearchWeb()
{
    return String("_Search the Web", String::ConstructFromLiteral);
}

String contextMenuItemTagLookUpInDictionary()
{
    return String("_Look Up in Dictionary", String::ConstructFromLiteral);
}

String contextMenuItemTagOpenLink()
{
    return String("_Open Link", String::ConstructFromLiteral);
}

String contextMenuItemTagIgnoreGrammar()
{
    return String("Ignore _Grammar", String::ConstructFromLiteral);
}

String contextMenuItemTagSpellingMenu()
{
    return String("Spelling and _Grammar", String::ConstructFromLiteral);
}

String contextMenuItemTagShowSpellingPanel(bool show)
{
	if(show)
		return String("_Show Spelling and Grammar", String::ConstructFromLiteral);
	else
		return String("_Hide Spelling and Grammar", String::ConstructFromLiteral);
}

String contextMenuItemTagCheckSpelling()
{
    return String("_Check Document Now", String::ConstructFromLiteral);
}

String contextMenuItemTagCheckSpellingWhileTyping()
{
    return String("Check Spelling While _Typing", String::ConstructFromLiteral);
}

String contextMenuItemTagCheckGrammarWithSpelling()
{
    return String("Check _Grammar With Spelling", String::ConstructFromLiteral);
}

String contextMenuItemTagFontMenu()
{
    return String("_Font", String::ConstructFromLiteral);
}

String contextMenuItemTagBold()
{
	return String("Tag Bold", String::ConstructFromLiteral);
}

String contextMenuItemTagItalic()
{
	return String("Tag Italic", String::ConstructFromLiteral);
}

String contextMenuItemTagUnderline()
{
	return String("Tag Underline", String::ConstructFromLiteral);
}

String contextMenuItemTagOutline()
{
    return String("_Outline", String::ConstructFromLiteral);
}

String contextMenuItemTagInspectElement()
{
    return String("Inspect _Element", String::ConstructFromLiteral);
}

String searchMenuNoRecentSearchesText()
{
    return String("No recent searches", String::ConstructFromLiteral);
}

String searchMenuRecentSearchesText()
{
    return String("Recent searches", String::ConstructFromLiteral);
}

String searchMenuClearRecentSearchesText()
{
    return String("_Clear recent searches", String::ConstructFromLiteral);
}

String AXDefinitionListTermText()
{
    return String("term", String::ConstructFromLiteral);
}

String AXDefinitionListDefinitionText()
{
    return String("definition", String::ConstructFromLiteral);
}

String AXButtonActionVerb()
{
    return String("press", String::ConstructFromLiteral);
}

String AXRadioButtonActionVerb()
{
    return String("select", String::ConstructFromLiteral);
}

String AXTextFieldActionVerb()
{
    return String("activate", String::ConstructFromLiteral);
}

String AXCheckedCheckBoxActionVerb()
{
    return String("uncheck", String::ConstructFromLiteral);
}

String AXUncheckedCheckBoxActionVerb()
{
    return String("check", String::ConstructFromLiteral);
}

String AXLinkActionVerb()
{
    return String("jump", String::ConstructFromLiteral);
}

String AXMenuListPopupActionVerb()
{
    return String();
}

String AXMenuListActionVerb()
{
    return String();
}

String multipleFileUploadText(unsigned numberOfFiles)
{
    // FIXME: If this file gets localized, this should really be localized as one string with a wildcard for the number.
    return String::number(numberOfFiles) + String(" files", String::ConstructFromLiteral);
}

String unknownFileSizeText()
{
    return String("Unknown", String::ConstructFromLiteral);
}

String imageTitle(const String& filename, const IntSize& size)
{
    notImplemented();
    return String();
}

#if ENABLE(VIDEO)

String mediaElementLoadingStateText()
{
    return String("Loading...", String::ConstructFromLiteral);
}

String mediaElementLiveBroadcastStateText()
{
    return String("Live Broadcast", String::ConstructFromLiteral);
}

String localizedMediaControlElementString(const String& name)
{
    if (name == "AudioElement")
        return String("audio element controller", String::ConstructFromLiteral);
    if (name == "VideoElement")
        return String("video element controller", String::ConstructFromLiteral);
    if (name == "MuteButton")
        return String("mute", String::ConstructFromLiteral);
    if (name == "UnMuteButton")
        return String("unmute", String::ConstructFromLiteral);
    if (name == "PlayButton")
        return String("play", String::ConstructFromLiteral);
    if (name == "PauseButton")
        return String("pause", String::ConstructFromLiteral);
    if (name == "Slider")
        return String("movie time", String::ConstructFromLiteral);
    if (name == "SliderThumb")
        return String("timeline slider thumb", String::ConstructFromLiteral);
    if (name == "RewindButton")
        return String("back 30 seconds", String::ConstructFromLiteral);
    if (name == "ReturnToRealtimeButton")
        return String("return to realtime", String::ConstructFromLiteral);
    if (name == "CurrentTimeDisplay")
        return String("elapsed time", String::ConstructFromLiteral);
    if (name == "TimeRemainingDisplay")
        return String("remaining time", String::ConstructFromLiteral);
    if (name == "StatusDisplay")
        return String("status", String::ConstructFromLiteral);
    if (name == "FullscreenButton")
        return String("fullscreen", String::ConstructFromLiteral);
    if (name == "SeekForwardButton")
        return String("fast forward", String::ConstructFromLiteral);
    if (name == "SeekBackButton")
        return String("fast reverse", String::ConstructFromLiteral);

    ASSERT_NOT_REACHED();
    
    return String();
}

String localizedMediaControlElementHelpText(const String& name)
{
    if (name == "AudioElement")
        return String("audio element playback controls and status display", String::ConstructFromLiteral);
    if (name == "VideoElement")
        return String("video element playback controls and status display", String::ConstructFromLiteral);
    if (name == "MuteButton")
        return String("mute audio tracks", String::ConstructFromLiteral);
    if (name == "UnMuteButton")
        return String("unmute audio tracks", String::ConstructFromLiteral);
    if (name == "PlayButton")
        return String("begin playback", String::ConstructFromLiteral);
    if (name == "PauseButton")
        return String("pause playback", String::ConstructFromLiteral);
    if (name == "Slider")
        return String("movie time scrubber", String::ConstructFromLiteral);
    if (name == "SliderThumb")
        return String("movie time scrubber thumb", String::ConstructFromLiteral);
    if (name == "RewindButton")
        return String("seek movie back 30 seconds", String::ConstructFromLiteral);
    if (name == "ReturnToRealtimeButton")
        return String("return streaming movie to real time", String::ConstructFromLiteral);
    if (name == "CurrentTimeDisplay")
        return String("current movie time in seconds", String::ConstructFromLiteral);
    if (name == "TimeRemainingDisplay")
        return String("number of seconds of movie remaining", String::ConstructFromLiteral);
    if (name == "StatusDisplay")
        return String("current movie status", String::ConstructFromLiteral);
    if (name == "SeekBackButton")
        return String("seek quickly back", String::ConstructFromLiteral);
    if (name == "SeekForwardButton")
        return String("seek quickly forward", String::ConstructFromLiteral);
    if (name == "FullscreenButton")
        return String("Play movie in fullscreen mode", String::ConstructFromLiteral);

    ASSERT_NOT_REACHED();
    return String();
}

String localizedMediaTimeDescription(float time)
{
    if (!isfinite(time))
        return String("indefinite time", String::ConstructFromLiteral);
    
    const int tmpStrLen = 256;
    char tmpStr[tmpStrLen];

    int seconds = (int)fabsf(time);
    int days = seconds / (60 * 60 * 24);
    int hours = seconds / (60 * 60);
    int minutes = (seconds / 60) % 60;
    seconds %= 60;

    if (days) {
    	snprintf(tmpStr, tmpStrLen, "%d days %d hours %d minutes %d seconds", days, hours, minutes, seconds);
    }
    else if (hours) {
    	snprintf(tmpStr, tmpStrLen, "%d hours %d minutes %d seconds", hours, minutes, seconds);
    }
    else if (minutes) {
    	snprintf(tmpStr, tmpStrLen, "%d minutes %d seconds", minutes, seconds);
    }
    else{
    	snprintf(tmpStr, tmpStrLen, "%d seconds", seconds);
    }
        
	return String(tmpStr);
}
#endif  // ENABLE(VIDEO)

String validationMessageValueMissingText()
{
    return String("value missing", String::ConstructFromLiteral);
}

String validationMessageValueMissingForCheckboxText()
{
    notImplemented();
    return validationMessageValueMissingText();
}

String validationMessageValueMissingForFileText()
{
    notImplemented();
    return validationMessageValueMissingText();
}

String validationMessageValueMissingForMultipleFileText()
{
    notImplemented();
    return validationMessageValueMissingText();
}

String validationMessageValueMissingForRadioText()
{
    notImplemented();
    return validationMessageValueMissingText();
}

String validationMessageValueMissingForSelectText()
{
    notImplemented();
    return validationMessageValueMissingText();
}

String validationMessageTypeMismatchText()
{
    notImplemented();
    return String("type mismatch", String::ConstructFromLiteral);
}

String validationMessageTypeMismatchForEmailText()
{
    notImplemented();
    return validationMessageTypeMismatchText();
}

String validationMessageTypeMismatchForMultipleEmailText()
{
    notImplemented();
    return validationMessageTypeMismatchText();
}

String validationMessageTypeMismatchForURLText()
{
    notImplemented();
    return validationMessageTypeMismatchText();
}

String validationMessagePatternMismatchText()
{
    return String("pattern mismatch", String::ConstructFromLiteral);
}

String validationMessageTooLongText(int, int)
{
    return String("too long", String::ConstructFromLiteral);
}

String validationMessageRangeUnderflowText(const String&)
{
    return String("range underflow", String::ConstructFromLiteral);
}

String validationMessageRangeOverflowText(const String&)
{
    return String("range overflow", String::ConstructFromLiteral);
}

String validationMessageStepMismatchText(const String&, const String&)
{
    return String("step mismatch", String::ConstructFromLiteral);
}

String missingPluginText()
{
    return String("Missing Plug-in", String::ConstructFromLiteral);
}

String crashedPluginText()
{
    notImplemented();
    return String("Plug-in Failure", String::ConstructFromLiteral);
}

String insecurePluginVersionText()
{
    notImplemented();
    return String();
}

String defaultDetailsSummaryText()
{
    return String("Details", String::ConstructFromLiteral);
}

}
