From c1e541b32b30fe34a0d3678399c3aed540c17f2e Mon Sep 17 00:00:00 2001 From: squidfunk Date: Wed, 18 Oct 2017 20:40:12 +0200 Subject: [PATCH] Added localization to clipboard --- material/base.html | 4 +++- material/partials/language.html | 2 ++ src/assets/javascripts/application.js | 23 +++++++++++++++++++++-- src/base.html | 2 ++ src/partials/language.html | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/material/base.html b/material/base.html index 6870f959e..fe3379b34 100644 --- a/material/base.html +++ b/material/base.html @@ -20,6 +20,8 @@ {% endif %} {% for key in [ + "clipboard-copy", + "clipboard-copied", "search-languages", "search-result-none", "search-result-one", @@ -162,7 +164,7 @@ {% endblock %} {% block scripts %} - + {% set languages = lang.t("search-languages").split(",") %} {% if languages | length and languages[0] != "" %} {% set path = base_url + "/assets/javascripts/lunr" %} diff --git a/material/partials/language.html b/material/partials/language.html index 39c8888fc..8ea2cbef9 100644 --- a/material/partials/language.html +++ b/material/partials/language.html @@ -1,5 +1,7 @@ {% macro t(key) %}{{ { "language": "en", + "clipboard-copy": "Copy to clipboard", + "clipboard-copied": "Copied to clipboard", "edit-link-title": "Edit this page", "footer-previous": "Previous", "footer-next": "Next", diff --git a/src/assets/javascripts/application.js b/src/assets/javascripts/application.js index 3463348a9..68a9f006a 100644 --- a/src/assets/javascripts/application.js +++ b/src/assets/javascripts/application.js @@ -25,6 +25,25 @@ import FastClick from "fastclick" import Material from "./components/Material" +/* ---------------------------------------------------------------------------- + * Functions + * ------------------------------------------------------------------------- */ + +/** + * Return the meta tag value for the given key + * + * @param {string} key - Meta name + * @param {string} [_] - Stop Flow complaining (TODO) + * + * @return {string} Meta content value + */ +const i18n = (key, _) => { // eslint-disable-line no-unused-vars + const meta = document.querySelector(`[name=i18n-${key}]`) + if (!(meta instanceof HTMLMetaElement)) + throw new ReferenceError + return meta.content +} + /* ---------------------------------------------------------------------------- * Application * ------------------------------------------------------------------------- */ @@ -73,7 +92,7 @@ function initialize(config) { // eslint-disable-line func-style /* Create button with message container */ const button = ( - @@ -101,7 +120,7 @@ function initialize(config) { // eslint-disable-line func-style /* Set message indicating success and show it */ message.classList.add("md-clipboard__message--active") - message.innerHTML = "Copied to clipboard" + message.innerHTML = i18n("clipboard-copied") /* Hide message after two seconds */ message.dataset.mdTimer = setTimeout(() => { diff --git a/src/base.html b/src/base.html index bb5678f53..511194bcd 100644 --- a/src/base.html +++ b/src/base.html @@ -56,6 +56,8 @@ {% for key in [ + "clipboard-copy", + "clipboard-copied", "search-languages", "search-result-none", "search-result-one", diff --git a/src/partials/language.html b/src/partials/language.html index 5e6c3d76e..d425bf73c 100644 --- a/src/partials/language.html +++ b/src/partials/language.html @@ -23,6 +23,8 @@ {% macro t(key) %}{{ { "language": "en", + "clipboard-copy": "Copy to clipboard", + "clipboard-copied": "Copied to clipboard", "edit-link-title": "Edit this page", "footer-previous": "Previous", "footer-next": "Next",