From: Ian Coleman Date: Thu, 15 Dec 2016 00:39:14 +0000 (+1100) Subject: Translation library can translate title attributes X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=commitdiff_plain;h=ede5137f6eafa4519830920765284b826e252a2f Translation library can translate title attributes --- diff --git a/src/js/translate.js b/src/js/translate.js index 89512df..a62d92b 100644 --- a/src/js/translate.js +++ b/src/js/translate.js @@ -6,7 +6,8 @@ // //
Test
//
keep em tag
-// +// +// // // Obtain all the phrases to be translated via js debug console: // @@ -21,7 +22,8 @@ // Translate.loadForeignPhrases("es", { // "Test": "Test in Spanish", // "keep em tag": "keep em tag in Spanish", -// "Example text": "Example text in Spanish" +// "Example placeholder": "Example placeholder in Spanish" +// "Example title": "Example title in Spanish" // }); // // In your UI put a listener for clicking on the Spanish button: @@ -72,10 +74,21 @@ Translate = new (function() { }, } + var title = { + selector: "[data-translate-title]", + getKey: function() { + return this.getAttribute("title").trim().replace(/\s+/g, " "); + }, + setPhrase: function(p) { + this.setAttribute("title", p); + }, + } + // Get elements to be translated var allEls = getEls(text) .concat(getEls(html)) - .concat(getEls(placeholder)); + .concat(getEls(placeholder)) + .concat(getEls(title)); // Provides access to phrases from a non-default language. // See phrases_en.js for example usage.