summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/chromeos/chromevox/host/testing/msgs.js
blob: f5ea04266eec358dd1818b7576abc837848d56b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


/**
 * @fileoverview Testing stub for messages.
 */

goog.provide('cvox.TestMsgs');

goog.require('cvox.AbstractMsgs');
goog.require('cvox.HostFactory');
goog.require('cvox.TestMessages');



/**
 * @constructor
 * @extends {cvox.AbstractMsgs}
 */
cvox.TestMsgs = function() {
  cvox.AbstractMsgs.call(this);
};
goog.inherits(cvox.TestMsgs, cvox.AbstractMsgs);


/**
 * Return the current locale.
 * @return {string} The locale.
 */
cvox.TestMsgs.prototype.getLocale = function() {
  return 'testing';
};


/**
 * Returns the message with the given message id from the ChromeVox namespace.
 *
 * @param {string} message_id The id.
 * @param {Array.<string>} opt_subs Substitution strings.
 * @return {string} The message.
 */
cvox.TestMsgs.prototype.getMsg = function(message_id, opt_subs) {
  if (!message_id) {
    var e = new Error();
    e.message = 'Message id required';
    throw e;
  }
  var message = cvox.TestMessages['chromevox_' + message_id];
  if (message == undefined) {
    var e = new Error();
    e.message = 'missing-msg: ' + message_id;
    throw e;
  }

  var messageString = message.message;
  if (opt_subs) {
    // Unshift a null to make opt_subs and message.placeholders line up.
    for (var i = 0; i < opt_subs.length; i++) {
      var placeholderObject = message.placeholders[i + 1];
      if (!placeholderObject) {
        var e = new Error();
        e.message = 'Bad placeholder ' + i + ' for message id ' + message_id;
        throw e;
      }
      var placeholder = message.placeholders[i + 1].content;
      messageString = messageString.replace(placeholder, opt_subs[i]);
    }
  }
  return messageString;
};


/**
 * Retuns a number formatted correctly.
 *
 * @param {number} num The number.
 * @return {string} The number in the correct locale.
 */
cvox.TestMsgs.prototype.getNumber = function(num) {
  return '' + num;
};

/** @override */
cvox.HostFactory.msgsConstructor = cvox.TestMsgs;