1/* pianod web client - internationalization/translation support 2 Copr. 2015-2017 Perette Barella/Devious Fish 3 All rights reserved. 4*/ 5 6 7 8 9var Translate = function () { 10 function Translate () { 11 /* Nothing */ 12 }; 13 14 /* Constants */ 15 var ERRORS = { 16 17 18 200: "Success", 19 203: "Start of data", 20 204: "No data or end of data", 21 206: "Match found", 22 207: "Value has been approximated", 23 210: "Command acknowledged but action is pending", 24 300: "Detail", 25 301: "Proxy settings invalid", 26 303: "Invalid playlist", 27 304: "Item not found", 28 400: "Bad command", 29 401: "Not authorized for requested action", 30 402: "Action failed", 31 403: "Already exists", 32 404: "Requested item not found", 33 405: "Action is not applicable to current state", 34 406: "Invalid login or password", 35 407: "Invalid parameter", 36 408: "Playlist personalization failed", 37 409: "Conflict encountered", 38 410: "Temporary failure, future completion unknown", 39 411: "Quota exceeded", 40 412: "Must be logged in", 41 413: "Not supported", 42 414: "Insufficient resources", 43 415: "Limit has been reached", 44 416: "Operation only valid on primary playlists", 45 417: "Wrong type for action", 46 418: "Persistent expression or value required", 47 460: "Action not supported by source", 48 461: "Value is not supported by source", 49 462: "Action not possible on media manager", 50 498: "There is a bug in pianod", 51 499: "Not implemented", 52 500: "Internal server error", 53 501: "Nothing to play", 54 502: "Network failure", 55 503: "Service shutting down", 56 504: "Authentication failure", 57 505: "Insufficent resources", 58 507: "Error communicating with Pandora", 59 508: "Command execution incomplete", 60 509: "Permission denied", 61 510: "Exception", 62 511: "Network timeout", 63 512: "Cannot open audio output", 64 'Bogus': 'Bogosity' 65 }; 66 67 68 69 var MESSAGES = { 70 "ERROR_LOGIN_FAILED": "Login failed", 71 "ERROR_CONNECTION_FAILED": "Connection failed.", 72 "ERROR_LOGIN_BAD_CREDENTIALS": "Bad user credentials.", 73 "CHECK_PORT_NUMBER": "Check port number.", 74 "LOGIN_SESSION_STARTING": "Opening connection to %1$s.", 75 "LOGIN_SESSION_ENDED": "Session ended.", 76 "STATUS_AUTHENTICATION_OK": "Authentication successful.", 77 78 79 "HEADING_ALBUM": "Album", 80 81 "HEADING_ARTIST": "Artist", 82 83 "HEADING_SONG": "Title", 84 85 "HEADING_GENRE": "Genre", 86 87 "HEADING_TYPE": "Type", 88 89 "HEADING_SEEDTYPE": "Seed Type", 90 91 "HEADING_PLAYLIST": "Playlist", 92 93 "HEADING_YEAR": "Year", 94 95 "HEADING_DURATION": "Duration", 96 97 "HEADING_ACTION": "Actions", 98 99 100 "Cap_song": "Song", 101 "Cap_artist": "Artist", 102 "Cap_album": "Album", 103 "Cap_playlist": "Playlist", 104 105 106 "lower_song": "song", 107 "lower_artist": "artist", 108 "lower_album": "album", 109 "lower_playlist": "playlist", 110 111 112 113 114 "PROMPT_CONFIRM_DELETE": "Are you sure you want to delete %1$s?", 115 "CONFIRM_DELETE": "%1$s deleted.", 116 "CONFIRM_ADD": "%1$s added.", 117 "CONFIRM_ADDED_TO": "Added %1$s to %2$s.", 118 "CONFIRM_CREATE": "%1$s created.", 119 "CONFIRM_RENAME": "%1$s renamed to %2$s.", 120 121 122 123 "ACTION_TABLE_QUE": "+Que", 124 "ACTION_TABLE_DEQUE": "✖Deque", 125 "ACTION_TABLE_SKIP": "Skip", 126 "ACTION_TABLE_SEED": "+Seed", 127 "ACTION_TABLE_UNSEED": "✖Remove Seed", 128 129 130 131 132 "CONFIRM_CLEAR_REQUESTS": "Request queue cleared.", 133 "SELECT_PLAYLISTS_NONE": "No playlists", 134 "ERROR_NO_USABLE_SOURCES": "No usable sources.", 135 "CONFIRM_RATE_OVERPLAYED": "Song rating temporarily downgraded.", 136 "CONFIRM_ADD_SEED_TYPE_TO": "Added %1$s seed to %2$s.", 137 "CONFIRM_DEQUEUED": "Requested music cancelled.", 138 "INDICATOR_AUTOTUNING": "∫", 139 "STATUS_NOTHING_PLAYING": "There is nothing playing right now.", 140 "ERROR_QUEUEHISTORY_RANGE": "No further items.", 141 142 143 144 145 "INFO_SEARCH_RESULTS_OMITTED": "Some results were omitted: ", 146 "ERROR_CHOOSE_PLAYLIST": "Please choose a target playlist.", 147 "ERROR_NEED_PLAYLIST_NAME": "Please provide a playlist name.", 148 "CONFIRM_QUEUED": "Requests queued.", 149 "ERROR_NEED_SEARCH_QUERY": "Please enter a search query.", 150 "MESSAGE_CREATE_WITH_ALL_RESULTS": "all search results", 151 "MESSAGE_CREATE_APPLIES_TARGET": "applies to target source", 152 153 154 155 156 "ERROR_NO_SOURCES": "Please provide some sources.", 157 "ERROR_NEED_SOURCE_SELECTION": "Please choose a source.", 158 "ERROR_NEED_SOURCE_TYPE": "Please choose a source type.", 159 "CONFIRM_SOURCE_ADDED": "Source added, may take a moment to be ready.", 160 "CONFIRM_SOURCE_REMOVED": "Source disconnected.", 161 "CONFIRM_SOURCE_SELECTED": "Source selected.", 162 163 164 "ADDSOURCE_NULL_PATH": "Please specify path/folder for music.", 165 166 167 168 169 "ACTION_SKIP": "Skip song", 170 171 "TOOLTIP_SKIP": "Skip the current song", 172 173 "ACTION_DEQUEUE": "Dequeue", 174 175 "TOOLTIP_DEQUEUE": "Cancel an upcoming song.", 176 177 "ACTION_RECUE": "Request song", 178 179 "TOOLTIP_RECUE": "Request this song again.", 180 181 182 "PROMPT_CREATE_PLAYLIST_FROM": "Create playlist from %1$s", 183 "PROMPT_ADD_SEED_FROM": "Add seed from %1$s", 184 185 186 187 188 "PROMPT_CONFIRM_DELETE_SEED": "Are you sure you want to remove the seed for %1$s?", 189 "ERROR_SELECT_PLAYLIST": "Please select a playlist.", 190 191 192 193 194 "HEADING_LISTENERS_ONLINE": "Listeners online:", 195 "ERROR_ACTIVITY_DISABLED": "Activity messages are disabled.", 196 "ERROR_YELL_NO_MESSAGE": "No message to yell.", 197 198 199 200 201 "PROMPT_OLD_PASSWORD": "Old password", 202 "PROMPT_NEW_PASSWORD": "New password", 203 "PROMPT_PIANOD_PASSWORD": "pianod password", 204 "PROMPT_SYSTEM_PASSWORD": "System password", 205 206 207 "PROMPT_CONFIRM_NO_PASSWORD": "This will clear %1$s's password so they can login without a password. This is insecure. Are you sure?", 208 "CONFIRM_USER_UPDATED": "User %1$s updated.", 209 "CONFIRM_PASSWORD_CHANGE": "Password has been updated.", 210 "ERROR_CANNOT_GET_USER_LIST": "Can not retrieve user list.", 211 "ERROR_PASSWORDS_UNMATCHED": "New passwords do not match.", 212 "ERROR_SELECT_USER": "Please select a user.", 213 "LABEL_KICK_VISITORS": "All visitors", 214 "CONFIRM_KICK": "User %1$s kicked.", 215 216 217 'Bogus': 'Bogosity' 218 }; 219 220 /* Private variables */ 221 222 /* Private functions */ 223 if (typeof (assert) == 'undefined') { 224 var assert = function () { }; 225 } 226 227 /* Return a function object, which will see all of 228 the above via the closure. */ 229 Translate.prototype.translate = function (value) { 230 if (typeof (value) == 'string') { 231 // Translate a string 232 var message = value in MESSAGES ? MESSAGES [value] : value; 233 // Perform printf-style positional string substitutions. 234 for (var i = 1; i < arguments.length; i++) { 235 message = message.replace (RegExp ("%" + i + "\\$s", "g"), arguments [i]); 236 } 237 return message; 238 } 239 // Translate a Football comm response. 240 assert (arguments.length == 1); 241 assert (typeof (value) == 'object'); 242 assert ('code' in value); 243 if (typeof (value) != 'object' || !('code' in value)) { 244 return 'Bad translation request'; 245 } 246 if (!(value.code in ERRORS)) { 247 return value.text; 248 } 249 // Replace value up to first colon. 250 var pieces = value.text.split (':'); 251 pieces [0] = ERRORS [value.code]; 252 return pieces.join (':') 253 }; 254 return Translate; 255}(); 256 257