diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-10 17:31:18 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-10 17:31:18 +0000 |
commit | 5c071edb2a53e90a7b6b12531ffe0441cd57803d (patch) | |
tree | 3c4b0b1b81a43b6bb34393c7bfc683603e9c243f /remoting | |
parent | eb8c1fd0a32f805e91bb711aa46f8108d3403c54 (diff) | |
download | chromium_src-5c071edb2a53e90a7b6b12531ffe0441cd57803d.zip chromium_src-5c071edb2a53e90a7b6b12531ffe0441cd57803d.tar.gz chromium_src-5c071edb2a53e90a7b6b12531ffe0441cd57803d.tar.bz2 |
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
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/resources/remoting_strings.grd | 3 | ||||
-rwxr-xr-x | remoting/tools/verify_resources.py | 8 | ||||
-rw-r--r-- | remoting/webapp/l10n.js | 40 | ||||
-rw-r--r-- | remoting/webapp/main.html | 5 |
4 files changed, 41 insertions, 15 deletions
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 @@ <message desc="The tool-tip shown when the user hovers over the 'delete host' button. Clicking this button removes the host from the list and disables connections to it." name="IDR_TOOLTIP_DELETE"> Disable remote connections to this computer </message> + <message desc="The tool-tip shown when the user hovers over the 'refresh host list' button. Clicking this button reloads the host list without reloading the app." name="IDR_TOOLTIP_REFRESH"> + Refresh the list of hosts + </message> <message desc="The tool-tip shown when the user hovers over the 'rename host' button. Clicking this button allows the host name to be edited in-place." name="IDR_TOOLTIP_RENAME"> Edit computer name </message> 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: <span i18n-content="PRODUCT_NAME"></span> - 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. <h2> <span i18n-content="MODE_ME2ME"></span> <span class="h2-secondary" id="host-list-loading-indicator"> - <a href="#" id="host-list-reload"> + <a href="#" id="host-list-reload" i18n-title="TOOLTIP_REFRESH"> <img src="reload.webp"> </a> <img src="spinner.gif" id="host-list-loading"> @@ -205,7 +205,8 @@ found in the LICENSE file. <div id="this-host-name" class="box-spacer"></div> <span id="this-host-rename" class="host-list-edit" - tabIndex="0"> + tabIndex="0" + i18n-title="TOOLTIP_RENAME"> <img id="this-host-rename" class="host-list-rename-icon" src="icon_pencil.webp"> |