OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview Defines methods related to retrieving translated messages. | 7 * @fileoverview Defines methods related to retrieving translated messages. |
8 */ | 8 */ |
9 | 9 |
10 goog.provide('Msgs'); | 10 goog.provide('Msgs'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * typos early. | 44 * typos early. |
45 * | 45 * |
46 * @param {string} messageId The id. | 46 * @param {string} messageId The id. |
47 * @param {Array<string>=} opt_subs Substitution strings. | 47 * @param {Array<string>=} opt_subs Substitution strings. |
48 * @return {string} The localized message. | 48 * @return {string} The localized message. |
49 */ | 49 */ |
50 Msgs.getMsg = function(messageId, opt_subs) { | 50 Msgs.getMsg = function(messageId, opt_subs) { |
51 var message = Msgs.Untranslated[messageId.toUpperCase()]; | 51 var message = Msgs.Untranslated[messageId.toUpperCase()]; |
52 if (message !== undefined) | 52 if (message !== undefined) |
53 return Msgs.applySubstitutions_(message, opt_subs); | 53 return Msgs.applySubstitutions_(message, opt_subs); |
54 message = chrome.i18n.getMessage( | 54 message = chrome.i18n.getMessage(Msgs.NAMESPACE_ + messageId, opt_subs); |
55 Msgs.NAMESPACE_ + messageId, opt_subs); | |
56 if (message == undefined || message == '') { | 55 if (message == undefined || message == '') { |
57 throw new Error('Invalid ChromeVox message id: ' + messageId); | 56 throw new Error('Invalid ChromeVox message id: ' + messageId); |
58 } | 57 } |
59 return message; | 58 return message; |
60 }; | 59 }; |
61 | 60 |
62 /** | 61 /** |
63 * Processes an HTML DOM, replacing text content with translated text messages | 62 * Processes an HTML DOM, replacing text content with translated text messages |
64 * on elements marked up for translation. Elements whose class attributes | 63 * on elements marked up for translation. Elements whose class attributes |
65 * contain the 'i18n' class name are expected to also have an msgid | 64 * contain the 'i18n' class name are expected to also have an msgid |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 /** | 97 /** |
99 * Gets a localized display name for a locale. | 98 * Gets a localized display name for a locale. |
100 * NOTE: Only a subset of locale identifiers are supported. See the | 99 * NOTE: Only a subset of locale identifiers are supported. See the |
101 * |CHROMEVOX_LOCALE_DICT| message. | 100 * |CHROMEVOX_LOCALE_DICT| message. |
102 * @param {string} locale On the form |ll| or |ll_CC|, where |ll| is | 101 * @param {string} locale On the form |ll| or |ll_CC|, where |ll| is |
103 * the language code and |CC| the country code. | 102 * the language code and |CC| the country code. |
104 * @return {string} The display name. | 103 * @return {string} The display name. |
105 */ | 104 */ |
106 Msgs.getLocaleDisplayName = function(locale) { | 105 Msgs.getLocaleDisplayName = function(locale) { |
107 if (!Msgs.localeNameDict_) { | 106 if (!Msgs.localeNameDict_) { |
108 Msgs.localeNameDict_ = /** @type {!Object<string>} */( | 107 Msgs.localeNameDict_ = |
109 JSON.parse(this.getMsg('locale_dict'))); | 108 /** @type {!Object<string>} */ (JSON.parse(this.getMsg('locale_dict'))); |
110 } | 109 } |
111 var name = Msgs.localeNameDict_[locale]; | 110 var name = Msgs.localeNameDict_[locale]; |
112 if (!name) { | 111 if (!name) { |
113 throw Error('Unsupported locale identifier: ' + locale); | 112 throw Error('Unsupported locale identifier: ' + locale); |
114 } | 113 } |
115 return name; | 114 return name; |
116 }; | 115 }; |
117 | 116 |
118 /** | 117 /** |
119 * Applies substitions of the form $N, where N is a number from 1 to 9, to a | 118 * Applies substitions of the form $N, where N is a number from 1 to 9, to a |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 TAG_TIME_BRL: ' ', | 181 TAG_TIME_BRL: ' ', |
183 /** Spoken when describing an ARIA value. */ | 182 /** Spoken when describing an ARIA value. */ |
184 ARIA_VALUE_NOW: '$1', | 183 ARIA_VALUE_NOW: '$1', |
185 /** Brailled when describing an ARIA value. */ | 184 /** Brailled when describing an ARIA value. */ |
186 ARIA_VALUE_NOW_BRL: '$1', | 185 ARIA_VALUE_NOW_BRL: '$1', |
187 /** Spoken when describing an ARIA value text. */ | 186 /** Spoken when describing an ARIA value text. */ |
188 ARIA_VALUE_TEXT: '$1', | 187 ARIA_VALUE_TEXT: '$1', |
189 /** Brailled when describing an ARIA value text. */ | 188 /** Brailled when describing an ARIA value text. */ |
190 ARIA_VALUE_TEXT_BRL: '$1', | 189 ARIA_VALUE_TEXT_BRL: '$1', |
191 }; | 190 }; |
OLD | NEW |