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

View File

@ -1,14 +1,50 @@
{ {
"appName": { "extensionName": {
"message": "Ext Starter", "message": "Shikiryu Bookmarklet",
"description": "The name of the extension." "description": "The name of the extension."
}, },
"appDescription": { "extensionDescription": {
"message": "Boilerplate for building cross browser extensions", "message": "Email a link for later read",
"description": "The description of the extension." "description": "The description of the extension."
}, },
"btnTooltip": { "optionsAndSettings": {
"message": "Ext Starter", "message": "Options & Settings",
"description": "Tooltip for the button." "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"> <meta charset="utf-8">
<link href="styles/options.css" rel="stylesheet"> <link href="styles/options.css" rel="stylesheet">
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<title>Options & Settings</title> <title data-message="optionsAndSettings"></title>
</head> </head>
<body class="wrap"> <body class="wrap">
<div class="grid"> <div class="grid">
<div class="unit whole center-on-mobiles"> <div class="unit whole center-on-mobiles">
<div class="heading"> <div class="heading">
<h1>Shikiryu Bookmarklet</h1> <h1 data-message="extensionName"></h1>
<p class="lead">Save this page by email for later read</p> <p class="lead" data-message="optionsPageSubtitle"></p>
</div> </div>
</div> </div>
</div> </div>
@ -24,12 +24,12 @@
<div class="grid"> <div class="grid">
<div class="unit whole center-on-mobiles"> <div class="unit whole center-on-mobiles">
<div class="option"> <div class="option">
<h5>URL</h5> <h5 data-message="optionsURL"></h5>
<input type="text" name="url" value="https://bookmarklet.shikiryu.com" /> <input type="text" name="url" value="https://bookmarklet.shikiryu.com" />
</div> </div>
<div class="option"> <div class="option">
<h5>Token</h5> <h5 data-message="optionsToken"></h5>
<input type="text" name="token" value="" /> <input type="text" name="token" value="" />
</div> </div>

View File

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

View File

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

View File

@ -16,13 +16,17 @@ storage.get('token', function(resp) {
urlInput.addEventListener("blur", function(e) { urlInput.addEventListener("blur", function(e) {
var value = this.value; var value = this.value;
storage.set({ url: value }, function() { storage.set({ url: value }, function() {
message.innerHTML = "URL changed!"; message.innerHTML = browser.i18n.getMessage("URLChanged");
}); });
}); });
tokenInput.addEventListener("blur", function(e) { tokenInput.addEventListener("blur", function(e) {
var value = this.value; var value = this.value;
storage.set({ token: value }, function() { 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); var tmpl = template(data);
displayContainer.innerHTML = tmpl; displayContainer.innerHTML = tmpl;
} else { } 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"); var data = e.target.getAttribute("data-bookmark");
ext.runtime.sendMessage({action: "perform-save", data: data}, function (response) { ext.runtime.sendMessage({action: "perform-save", data: data}, function (response) {
if (response && response.action === "saved") { if (response && response.action === "saved") {
renderMessage("Your bookmark was saved successfully!"); renderMessage(browser.i18n.getMessage("savedSuccessfully"));
} else { } 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"); var optionsLink = document.querySelector(".js-options");
optionsLink.addEventListener("click", function(e) { optionsLink.addEventListener("click", function(e) {
e.preventDefault(); e.preventDefault();