Skip to content
Snippets Groups Projects
Commit c1e541b3 authored by squidfunk's avatar squidfunk Committed by Martin Donath
Browse files

Added localization to clipboard

parent 67034543
Branches
Tags
No related merge requests found
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
<meta name="author" content="{{ config.site_author }}"> <meta name="author" content="{{ config.site_author }}">
{% endif %} {% endif %}
{% for key in [ {% for key in [
"clipboard-copy",
"clipboard-copied",
"search-languages", "search-languages",
"search-result-none", "search-result-none",
"search-result-one", "search-result-one",
...@@ -162,7 +164,7 @@ ...@@ -162,7 +164,7 @@
{% endblock %} {% endblock %}
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-8591b4244d.js"></script> <script src="{{ base_url }}/assets/javascripts/application-ff1c1336b6.js"></script>
{% set languages = lang.t("search-languages").split(",") %} {% set languages = lang.t("search-languages").split(",") %}
{% if languages | length and languages[0] != "" %} {% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %} {% set path = base_url + "/assets/javascripts/lunr" %}
......
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"language": "en", "language": "en",
"clipboard-copy": "Copy to clipboard",
"clipboard-copied": "Copied to clipboard",
"edit-link-title": "Edit this page", "edit-link-title": "Edit this page",
"footer-previous": "Previous", "footer-previous": "Previous",
"footer-next": "Next", "footer-next": "Next",
......
...@@ -25,6 +25,25 @@ import FastClick from "fastclick" ...@@ -25,6 +25,25 @@ import FastClick from "fastclick"
import Material from "./components/Material" 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 * Application
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
...@@ -73,7 +92,7 @@ function initialize(config) { // eslint-disable-line func-style ...@@ -73,7 +92,7 @@ function initialize(config) { // eslint-disable-line func-style
/* Create button with message container */ /* Create button with message container */
const button = ( const button = (
<button class="md-clipboard" title="Copy to clipboard" <button class="md-clipboard" title={i18n("clipboard-copy")}
data-clipboard-target={`#${id} pre, #${id} code`}> data-clipboard-target={`#${id} pre, #${id} code`}>
<span class="md-clipboard__message"></span> <span class="md-clipboard__message"></span>
</button> </button>
...@@ -101,7 +120,7 @@ function initialize(config) { // eslint-disable-line func-style ...@@ -101,7 +120,7 @@ function initialize(config) { // eslint-disable-line func-style
/* Set message indicating success and show it */ /* Set message indicating success and show it */
message.classList.add("md-clipboard__message--active") message.classList.add("md-clipboard__message--active")
message.innerHTML = "Copied to clipboard" message.innerHTML = i18n("clipboard-copied")
/* Hide message after two seconds */ /* Hide message after two seconds */
message.dataset.mdTimer = setTimeout(() => { message.dataset.mdTimer = setTimeout(() => {
......
...@@ -56,6 +56,8 @@ ...@@ -56,6 +56,8 @@
<!-- Localization --> <!-- Localization -->
{% for key in [ {% for key in [
"clipboard-copy",
"clipboard-copied",
"search-languages", "search-languages",
"search-result-none", "search-result-none",
"search-result-one", "search-result-one",
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
<!-- Translations --> <!-- Translations -->
{% macro t(key) %}{{ { {% macro t(key) %}{{ {
"language": "en", "language": "en",
"clipboard-copy": "Copy to clipboard",
"clipboard-copied": "Copied to clipboard",
"edit-link-title": "Edit this page", "edit-link-title": "Edit this page",
"footer-previous": "Previous", "footer-previous": "Previous",
"footer-next": "Next", "footer-next": "Next",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment