Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: remoting/webapp/me2mom/l10n.js

Issue 9148043: Rename webapp_it2me to remoting_webapp and move it from webapp/me2mom to webapp/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add webapp_it2me back Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/webapp/me2mom/host_table_entry.js ('k') | remoting/webapp/me2mom/log_to_server.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* Copyright (c) 2011 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 var l10n = l10n || {};
7
8 /**
9 * Localize an element by setting its innerText according to the specified tag
10 * and an optional set of substitutions.
11 * @param {Element} element The element to localize.
12 * @param {string} tag The localization tag.
13 * @param {(string|Array)=} opt_substitutions An optional set of substitution
14 * strings corresponding to the "placeholders" attributes in messages.json.
15 * @return {boolean} True if the localization was successful; false otherwise.
16 */
17 l10n.localizeElementFromTag = function(element, tag, opt_substitutions) {
18 var translation = chrome.i18n.getMessage(tag, opt_substitutions);
19 if (translation) {
20 element.innerHTML = translation;
21 } else {
22 console.error('Missing translation for "' + tag + '":', element);
23 }
24 return translation != null;
25 };
26
27 /**
28 * Localize an element by setting its innerText according to its i18n-content
29 * attribute, and an optional set of substitutions.
30 * @param {Element} element The element to localize.
31 * @param {(string|Array)=} opt_substitutions An optional set of substitution
32 * strings corresponding to the "placeholders" attributes in messages.json.
33 * @return {boolean} True if the localization was successful; false otherwise.
34 */
35 l10n.localizeElement = function(element, opt_substitutions) {
36 var tag = element.getAttribute('i18n-content');
37 return l10n.localizeElementFromTag(element, tag, opt_substitutions);
38 };
39
40 /**
41 * Localize all tags with the i18n-content attribute, using i18n-data-n
42 * attributes to specify any placeholder substitutions.
43 */
44 l10n.localize = function() {
45 var elements = document.querySelectorAll('[i18n-content]');
46 for (var i = 0; i < elements.length; ++i) {
47 /** @type {Element} */ var element = elements[i];
48 var substitutions = null;
49 for (var j = 1; j < 9; ++j) {
50 var attr = 'i18n-value-' + j;
51 if (element.hasAttribute(attr)) {
52 if (!substitutions) {
53 substitutions = [];
54 }
55 substitutions.push(element.getAttribute(attr));
56 } else {
57 break;
58 }
59 }
60 l10n.localizeElement(element, substitutions);
61 }
62 };
OLDNEW
« no previous file with comments | « remoting/webapp/me2mom/host_table_entry.js ('k') | remoting/webapp/me2mom/log_to_server.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698