| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 | |
| 6 /** | |
| 7 * @fileoverview Testing stub for messages. | |
| 8 */ | |
| 9 | |
| 10 goog.provide('cvox.TestMsgs'); | |
| 11 | |
| 12 goog.require('cvox.AbstractMsgs'); | |
| 13 goog.require('cvox.HostFactory'); | |
| 14 goog.require('cvox.TestMessages'); | |
| 15 | |
| 16 | |
| 17 | |
| 18 /** | |
| 19 * @constructor | |
| 20 * @extends {cvox.AbstractMsgs} | |
| 21 */ | |
| 22 cvox.TestMsgs = function() { | |
| 23 cvox.AbstractMsgs.call(this); | |
| 24 }; | |
| 25 goog.inherits(cvox.TestMsgs, cvox.AbstractMsgs); | |
| 26 | |
| 27 | |
| 28 /** | |
| 29 * Return the current locale. | |
| 30 * @return {string} The locale. | |
| 31 */ | |
| 32 cvox.TestMsgs.prototype.getLocale = function() { | |
| 33 return 'testing'; | |
| 34 }; | |
| 35 | |
| 36 | |
| 37 /** | |
| 38 * Returns the message with the given message id from the ChromeVox namespace. | |
| 39 * | |
| 40 * @param {string} message_id The id. | |
| 41 * @param {Array.<string>} opt_subs Substitution strings. | |
| 42 * @return {string} The message. | |
| 43 */ | |
| 44 cvox.TestMsgs.prototype.getMsg = function(message_id, opt_subs) { | |
| 45 if (!message_id) { | |
| 46 throw Error('Message id required'); | |
| 47 } | |
| 48 var message = cvox.TestMessages[('chromevox_' + message_id).toUpperCase()]; | |
| 49 if (message == undefined) { | |
| 50 throw Error('missing-msg: ' + message_id); | |
| 51 } | |
| 52 | |
| 53 var messageString = message.message; | |
| 54 if (opt_subs) { | |
| 55 // Unshift a null to make opt_subs and message.placeholders line up. | |
| 56 for (var i = 0; i < opt_subs.length; i++) { | |
| 57 messageString = messageString.replace('$' + (i + 1), opt_subs[i]); | |
| 58 } | |
| 59 } | |
| 60 return messageString; | |
| 61 }; | |
| 62 | |
| 63 | |
| 64 /** | |
| 65 * Retuns a number formatted correctly. | |
| 66 * | |
| 67 * @param {number} num The number. | |
| 68 * @return {string} The number in the correct locale. | |
| 69 */ | |
| 70 cvox.TestMsgs.prototype.getNumber = function(num) { | |
| 71 return '' + num; | |
| 72 }; | |
| 73 | |
| 74 /** | |
| 75 * Cosntructor for the host factory. | |
| 76 */ | |
| 77 cvox.HostFactory.msgsConstructor = cvox.TestMsgs; | |
| OLD | NEW |