From 5c071edb2a53e90a7b6b12531ffe0441cd57803d Mon Sep 17 00:00:00 2001 From: "jamiewalch@chromium.org" Date: Tue, 10 Sep 2013 17:31:18 +0000 Subject: Add support for i18n-title. Previously, we only had one tool-tip defined in the HTML markup, and its l10n was hard-coded. This CL adds a generic mechanism, uses it for the local host edit button and adds a tool-tip to the host list refresh button. Review URL: https://chromiumcodereview.appspot.com/23923009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222295 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/resources/remoting_strings.grd | 3 +++ remoting/tools/verify_resources.py | 8 +++++-- remoting/webapp/l10n.js | 40 ++++++++++++++++++++++++--------- remoting/webapp/main.html | 5 +++-- 4 files changed, 41 insertions(+), 15 deletions(-) (limited to 'remoting') diff --git a/remoting/resources/remoting_strings.grd b/remoting/resources/remoting_strings.grd index 08d64e2..0de10d8 100644 --- a/remoting/resources/remoting_strings.grd +++ b/remoting/resources/remoting_strings.grd @@ -599,6 +599,9 @@ Disable remote connections to this computer + + Refresh the list of hosts + Edit computer name diff --git a/remoting/tools/verify_resources.py b/remoting/tools/verify_resources.py index eb59b2f..5623228 100755 --- a/remoting/tools/verify_resources.py +++ b/remoting/tools/verify_resources.py @@ -12,8 +12,9 @@ annotated with the string "i18n-content", for example: This script also recognises localized strings in HTML and manifest.json files: - HTML: - or ...i18n-value-name-1="BUTTON_NAME"... + HTML: i18n-content="PRODUCT_NAME" + or i18n-value-name-1="BUTTON_NAME" + or i18n-title="TOOLTIP_NAME" manifest.json: __MSG_PRODUCT_NAME__ Note that these forms must be exact; extra spaces are not permitted, though @@ -55,6 +56,9 @@ def ExtractTagFromLine(file_type, line): # HTML-style (tags) m = re.search('i18n-content=[\'"]([^\'"]*)[\'"]', line) if m: return m.group(1) + # HTML-style (titles) + m = re.search('i18n-title=[\'"]([^\'"]*)[\'"]', line) + if m: return m.group(1) # HTML-style (substitutions) m = re.search('i18n-value-name-[1-9]=[\'"]([^\'"]*)[\'"]', line) if m: return m.group(1) diff --git a/remoting/webapp/l10n.js b/remoting/webapp/l10n.js index 2df3e50..1774fb9 100644 --- a/remoting/webapp/l10n.js +++ b/remoting/webapp/l10n.js @@ -6,8 +6,27 @@ var l10n = l10n || {}; /** + * Localize a tag, returning the tag itself and logging an error if no + * translation exists. + * + * @param {string} tag The localization tag. + * @param {(string|Array)=} opt_substitutions An optional set of substitution + * strings corresponding to the "placeholders" attributes in messages.json. + * @return {string} The translated tag. + */ +l10n.getTranslationOrError = function(tag, opt_substitutions) { + var translation = chrome.i18n.getMessage(tag, opt_substitutions); + if (translation) { + return translation; + } + console.error('Missing translation for "' + tag + '"'); + return tag; +}; + +/** * Localize an element by setting its innerText according to the specified tag * and an optional set of substitutions. + * * @param {Element} element The element to localize. * @param {string} tag The localization tag. * @param {(string|Array)=} opt_substitutions An optional set of substitution @@ -18,11 +37,7 @@ var l10n = l10n || {}; */ l10n.localizeElementFromTag = function(element, tag, opt_substitutions, opt_asHtml) { - var translation = chrome.i18n.getMessage(tag, opt_substitutions); - if (!translation) { - console.error('Missing translation for "' + tag + '":', element); - translation = tag; // Make errors more obvious - } + var translation = l10n.getTranslationOrError(tag, opt_substitutions); if (opt_asHtml) { element.innerHTML = translation; } else { @@ -34,6 +49,7 @@ l10n.localizeElementFromTag = function(element, tag, opt_substitutions, /** * Localize an element by setting its innerText according to its i18n-content * attribute, and an optional set of substitutions. + * * @param {Element} element The element to localize. * @param {(string|Array)=} opt_substitutions An optional set of substitution * strings corresponding to the "placeholders" attributes in messages.json. @@ -56,7 +72,7 @@ l10n.localizeElement = function(element, opt_substitutions, opt_asHtml) { * HTML iff there are any substitutions. */ l10n.localize = function() { - var elements = document.querySelectorAll('[i18n-content]'); + var elements = document.querySelectorAll('[i18n-content],[i18n-title]'); for (var i = 0; i < elements.length; ++i) { /** @type {Element} */ var element = elements[i]; var substitutions = []; @@ -78,10 +94,12 @@ l10n.localize = function() { break; } } - l10n.localizeElement(element, substitutions, substitutions.length != 0); - // Localize tool-tips - // TODO(jamiewalch): Move this logic to the html document. - var editButton = document.getElementById('this-host-rename'); - editButton.title = chrome.i18n.getMessage(/*i18n-content*/'TOOLTIP_RENAME'); + var titleTag = element.getAttribute('i18n-title'); + if (titleTag) { + element.title = l10n.getTranslationOrError(titleTag, substitutions); + } else { + l10n.localizeElement(element, substitutions, + substitutions.length != 0); + } } }; diff --git a/remoting/webapp/main.html b/remoting/webapp/main.html index 472b91a..b6f9f11 100644 --- a/remoting/webapp/main.html +++ b/remoting/webapp/main.html @@ -156,7 +156,7 @@ found in the LICENSE file.

- + @@ -205,7 +205,8 @@ found in the LICENSE file.
+ tabIndex="0" + i18n-title="TOOLTIP_RENAME"> -- cgit v1.1