🌐 Add translations

This commit is contained in:
Clement Desmidt 2018-10-01 23:55:22 +02:00
parent 8679ac915f
commit 3943e86d0b
8 changed files with 126 additions and 29 deletions

View File

@ -2,7 +2,7 @@
"name": "Shikiryu Bookmarklet",
"version": "0.0.1",
"manifest_version": 2,
"description": "Email a link for later read",
"description": "__MSG_extensionDescription__",
"icons": {
"16": "icons/icon-16.png",
"128": "icons/icon-128.png"
@ -46,7 +46,7 @@
},
"applications": {
"gecko": {
"id": "bookrmarklet@shikiryu.com"
"id": "bookmarklet@shikiryu.com"
}
}
}

View File

@ -1,14 +1,50 @@
{
"appName": {
"message": "Ext Starter",
"extensionName": {
"message": "Shikiryu Bookmarklet",
"description": "The name of the extension."
},
"appDescription": {
"message": "Boilerplate for building cross browser extensions",
"extensionDescription": {
"message": "Email a link for later read",
"description": "The description of the extension."
},
"btnTooltip": {
"message": "Ext Starter",
"description": "Tooltip for the button."
"optionsAndSettings": {
"message": "Options & Settings",
"description": "Options page title."
},
"optionsPageSubtitle": {
"message": "Save this page by email for later read",
"description": "Options page subtitle."
},
"optionsURL": {
"message": "URL:",
"description": "URL label"
},
"optionsToken": {
"message": "Token:",
"description": "Token label"
},
"URLChanged": {
"message": "URL changed!",
"description": "Message when URL is changed."
},
"tokenSaved": {
"message": "Token saved!",
"description": "Message when token is changed."
},
"cantExtractTitle": {
"message": "Sorry, could not extract this page's title and URL",
"description": "Message when we could not extract the page's title and URL"
},
"savedSuccessfully": {
"message": "Your bookmark was saved successfully!",
"description": "Message when your bookmark was saved successfully"
},
"unknownError": {
"message": "Sorry, there was an error while saving your bookmark.",
"description": "Message when there was an error while saving your bookmark."
},
"defaultURL": {
"message": "https://bookmarklet.shikiryu.com",
"description": "Default URL"
}
}

View File

@ -0,0 +1,50 @@
{
"extensionName": {
"message": "Shikiryu Bookmarklet",
"description": "The name of the extension."
},
"extensionDescription": {
"message": "Envoyez vous un lien par mail pour plus tard",
"description": "The description of the extension."
},
"optionsAndSettings": {
"message": "Options & Paramètres",
"description": "Options page title."
},
"optionsPageSubtitle": {
"message": "Sauvegarde cette page pour lecture ultérieure",
"description": "Options page subtitle."
},
"optionsURL": {
"message": "Lien :",
"description": "URL label"
},
"optionsToken": {
"message": "Jeton :",
"description": "Token label"
},
"URLChanged": {
"message": "URL changed!",
"description": "Message when URL is changed."
},
"tokenSaved": {
"message": "Token saved!",
"description": "Message when token is changed."
},
"cantExtractTitle": {
"message": "Sorry, could not extract this page's title and URL",
"description": "Message when we could not extract the page's title and URL"
},
"savedSuccessfully": {
"message": "Your bookmark was saved successfully!",
"description": "Message when your bookmark was saved successfully"
},
"unknownError": {
"message": "Sorry, there was an error while saving your bookmark.",
"description": "Message when there was an error while saving your bookmark."
},
"defaultURL": {
"message": "https://bookmarklet.shikiryu.com",
"description": "Default URL"
}
}

View File

@ -4,14 +4,14 @@
<meta charset="utf-8">
<link href="styles/options.css" rel="stylesheet">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Options & Settings</title>
<title data-message="optionsAndSettings"></title>
</head>
<body class="wrap">
<div class="grid">
<div class="unit whole center-on-mobiles">
<div class="heading">
<h1>Shikiryu Bookmarklet</h1>
<p class="lead">Save this page by email for later read</p>
<h1 data-message="extensionName"></h1>
<p class="lead" data-message="optionsPageSubtitle"></p>
</div>
</div>
</div>
@ -24,12 +24,12 @@
<div class="grid">
<div class="unit whole center-on-mobiles">
<div class="option">
<h5>URL</h5>
<h5 data-message="optionsURL"></h5>
<input type="text" name="url" value="https://bookmarklet.shikiryu.com" />
</div>
<div class="option">
<h5>Token</h5>
<h5 data-message="optionsToken"></h5>
<input type="text" name="token" value="" />
</div>

View File

@ -6,16 +6,19 @@
</head>
<body>
<div id="app" class="popup-content">
<h1 class="app-name">Extension Boilerplate</h1>
<h1 data-message="extensionName"></h1>
<p class="lead" data-message="optionsPageSubtitle"></p>
<div id="display-container"></div>
<footer>
<p>
<small>
<a href="#" class="js-options">Options</a>
</small>
</p>
<footer class="main-footer">
<div class="grid">
<div class="unit whole center-on-mobiles">
<p class="text-center text-muted">
&copy; Shikiryu (thanks to https://github.com/EmailThis/extension-boilerplate)
</p>
</div>
</div>
</footer>
</div>

View File

@ -11,10 +11,7 @@ ext.runtime.onMessage.addListener(
url = resp.url;
token = resp.token;
var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token);
console.log("Destination: ", destination);
fetch(destination).then(function(response) {
console.log(response);
sendResponse({ action: "saved" });
});
});

View File

@ -16,13 +16,17 @@ storage.get('token', function(resp) {
urlInput.addEventListener("blur", function(e) {
var value = this.value;
storage.set({ url: value }, function() {
message.innerHTML = "URL changed!";
message.innerHTML = browser.i18n.getMessage("URLChanged");
});
});
tokenInput.addEventListener("blur", function(e) {
var value = this.value;
storage.set({ token: value }, function() {
message.innerHTML = "Token saved!";
message.innerHTML = browser.i18n.getMessage("tokenSaved");
});
});
document.querySelectorAll("[data-message]").forEach(function(elt) {
elt.innerHTML = browser.i18n.getMessage(elt.dataset.message);
});

View File

@ -33,7 +33,7 @@ var renderBookmark = (data) => {
var tmpl = template(data);
displayContainer.innerHTML = tmpl;
} else {
renderMessage("Sorry, could not extract this page's title and URL")
renderMessage(browser.i18n.getMessage("cantExtractTitle"));
}
}
@ -48,14 +48,21 @@ popup.addEventListener("click", function(e) {
var data = e.target.getAttribute("data-bookmark");
ext.runtime.sendMessage({action: "perform-save", data: data}, function (response) {
if (response && response.action === "saved") {
renderMessage("Your bookmark was saved successfully!");
renderMessage(browser.i18n.getMessage("savedSuccessfully"));
} else {
renderMessage("Sorry, there was an error while saving your bookmark.");
renderMessage(browser.i18n.getMessage("unknownError"));
}
});
}
});
var dataMessages = document.querySelectorAll("[data-message]");
console.dir(dataMessages);
[].forEach.call(dataMessages, function(elt) {
console.log(elt.dataset.message);
elt.innerHTML = browser.i18n.getMessage(elt.dataset.message);
});
var optionsLink = document.querySelector(".js-options");
optionsLink.addEventListener("click", function(e) {
e.preventDefault();