Translate "Random instance (none selected)" (#158)

This commit is contained in:
SimonBrazell 2021-01-12 20:29:26 +11:00
parent 23faeec4b5
commit bd783485a8
4 changed files with 33 additions and 9 deletions

View File

@ -138,5 +138,9 @@
"bibliogramRandomPool": {
"message": "Bibliogram random instance pool (comma-separated)",
"description": "Label for 'Bibliogram random instance pool (comma-separated)' option (options)."
},
"randomInstancePlaceholder": {
"message": "Random instance (none selected)",
"description": "Input placeholder for provider instance settings that select a random instance from a pool when none is selected"
}
}

View File

@ -1,19 +1,35 @@
window.browser = window.browser || window.chrome;
function localisePage() {
var data = document.querySelectorAll("[data-localise]");
for (var i in data)
if (data.hasOwnProperty(i)) {
var obj = data[i];
var tag = obj.getAttribute("data-localise").toString();
var msg = tag.replace(/__MSG_(\w+)__/g, function (_match, v1) {
function getMessage(tag) {
return tag.replace(/__MSG_(\w+)__/g, function (_match, v1) {
return v1 ? browser.i18n.getMessage(v1) : null;
});
}
function localisePage() {
let elements = document.querySelectorAll("[data-localise]");
for (let i in elements)
if (elements.hasOwnProperty(i)) {
let obj = elements[i];
let tag = obj.getAttribute("data-localise").toString();
let msg = getMessage(tag);
if (msg && msg !== tag) obj.textContent = msg;
}
let placeholders = document.querySelectorAll("[data-localise-placeholder]");
for (let i in placeholders)
if (placeholders.hasOwnProperty(i)) {
let obj = placeholders[i];
let tag = obj.getAttribute("data-localise-placeholder").toString();
let msg = getMessage(tag);
if (msg && msg !== tag) obj.placeholder = msg;
}
}
localisePage();

View File

@ -1,7 +1,7 @@
{
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "1.1.45",
"version": "1.1.46",
"manifest_version": 2,
"background": {
"page": "pages/background/background.html",

View File

@ -171,6 +171,7 @@
id="nitter-instance"
type="url"
name="nitter-instance"
data-localise-placeholder="__MSG_randomInstancePlaceholder__"
placeholder="Random instance (none selected)"
/>
</div>
@ -181,6 +182,7 @@
<input
id="invidious-instance"
type="url"
data-localise-placeholder="__MSG_randomInstancePlaceholder__"
placeholder="Random instance (none selected)"
/>
</div>
@ -191,6 +193,7 @@
<input
id="bibliogram-instance"
type="url"
data-localise-placeholder="__MSG_randomInstancePlaceholder__"
placeholder="Random instance (none selected)"
/>
</div>
@ -221,6 +224,7 @@
<input
id="search-engine-instance"
type="url"
data-localise-placeholder="__MSG_randomInstancePlaceholder__"
placeholder="Random instance (none selected)"
/>
</div>