mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 15:06:15 -04:00
Use default translation if any placeholder is missing in the translation string
This commit is contained in:
parent
29bede6109
commit
25d6595a8f
2 changed files with 30 additions and 7 deletions
|
@ -118,7 +118,7 @@ class Localization {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static getTranslation(key, attr=null, data={}, useDefault=false) {
|
static getTranslation(key, attr = null, data = {}, useDefault = false) {
|
||||||
const keys = key.split(".");
|
const keys = key.split(".");
|
||||||
|
|
||||||
let translationCandidates = useDefault
|
let translationCandidates = useDefault
|
||||||
|
@ -139,27 +139,45 @@ class Localization {
|
||||||
translation = translationCandidates[lastKey];
|
translation = translationCandidates[lastKey];
|
||||||
|
|
||||||
for (let j in data) {
|
for (let j in data) {
|
||||||
translation = translation.replace(`{{${j}}}`, data[j]);
|
if (translation.includes(`{{${j}}}`)) {
|
||||||
|
translation = translation.replace(`{{${j}}}`, data[j]);
|
||||||
|
} else {
|
||||||
|
console.warn(`Translation for your language ${Localization.locale.toUpperCase()} misses at least one data placeholder:`, key, attr, data);
|
||||||
|
Localization.logHelpCallKey(key);
|
||||||
|
Localization.logHelpCall();
|
||||||
|
translation = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
translation = "";
|
translation = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!translation) {
|
if (!translation) {
|
||||||
if (!useDefault) {
|
if (!useDefault) {
|
||||||
translation = this.getTranslation(key, attr, data, true);
|
|
||||||
console.warn(`Missing translation entry for your language ${Localization.locale.toUpperCase()}. Using ${Localization.defaultLocale.toUpperCase()} instead.`, key, attr);
|
console.warn(`Missing translation entry for your language ${Localization.locale.toUpperCase()}. Using ${Localization.defaultLocale.toUpperCase()} instead.`, key, attr);
|
||||||
console.warn(`Translate this string here: https://hosted.weblate.org/browse/pairdrop/pairdrop-spa/${Localization.locale.toLowerCase()}/?q=${key}`)
|
Localization.logHelpCallKey(key);
|
||||||
console.log("Help translating PairDrop: https://hosted.weblate.org/engage/pairdrop/");
|
Localization.logHelpCall();
|
||||||
|
translation = this.getTranslation(key, attr, data, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.warn("Missing translation in default language:", key, attr);
|
console.warn("Missing translation in default language:", key, attr);
|
||||||
|
Localization.logHelpCall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Localization.escapeHTML(translation);
|
return Localization.escapeHTML(translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static logHelpCall() {
|
||||||
|
console.log("Help translating PairDrop: https://hosted.weblate.org/engage/pairdrop/");
|
||||||
|
}
|
||||||
|
|
||||||
|
static logHelpCallKey(key) {
|
||||||
|
console.warn(`Translate this string here: https://hosted.weblate.org/browse/pairdrop/pairdrop-spa/${Localization.locale.toLowerCase()}/?q=${key}`);
|
||||||
|
}
|
||||||
|
|
||||||
static escapeHTML(unsafeText) {
|
static escapeHTML(unsafeText) {
|
||||||
let div = document.createElement('div');
|
let div = document.createElement('div');
|
||||||
div.innerText = unsafeText;
|
div.innerText = unsafeText;
|
||||||
|
|
|
@ -235,6 +235,7 @@ class PeersUI {
|
||||||
|
|
||||||
Events.on('share-mode-pointerdown', this._activateCallback);
|
Events.on('share-mode-pointerdown', this._activateCallback);
|
||||||
|
|
||||||
|
const sharedText = Localization.getTranslation("instructions.activate-share-mode-shared-text");
|
||||||
const andOtherFilesPlural = Localization.getTranslation("instructions.activate-share-mode-and-other-files-plural", null, {count: files.length-1});
|
const andOtherFilesPlural = Localization.getTranslation("instructions.activate-share-mode-and-other-files-plural", null, {count: files.length-1});
|
||||||
const andOtherFiles = Localization.getTranslation("instructions.activate-share-mode-and-other-file");
|
const andOtherFiles = Localization.getTranslation("instructions.activate-share-mode-and-other-file");
|
||||||
|
|
||||||
|
@ -257,7 +258,7 @@ class PeersUI {
|
||||||
else {
|
else {
|
||||||
// text shared
|
// text shared
|
||||||
descriptorItem = text.replace(/\s/g," ");
|
descriptorItem = text.replace(/\s/g," ");
|
||||||
descriptorComplete = descriptorItem;
|
descriptorComplete = sharedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
|
@ -308,6 +309,7 @@ class PeersUI {
|
||||||
this.$shareModeDescriptorItem.innerText = descriptorItem;
|
this.$shareModeDescriptorItem.innerText = descriptorItem;
|
||||||
|
|
||||||
this.shareMode.active = true;
|
this.shareMode.active = true;
|
||||||
|
this.shareMode.descriptor = descriptorComplete;
|
||||||
this.shareMode.files = files;
|
this.shareMode.files = files;
|
||||||
this.shareMode.text = text;
|
this.shareMode.text = text;
|
||||||
|
|
||||||
|
@ -334,6 +336,7 @@ class PeersUI {
|
||||||
if (!this.shareMode.active) return;
|
if (!this.shareMode.active) return;
|
||||||
|
|
||||||
this.shareMode.active = false;
|
this.shareMode.active = false;
|
||||||
|
this.shareMode.descriptor = "";
|
||||||
this.shareMode.files = [];
|
this.shareMode.files = [];
|
||||||
this.shareMode.text = "";
|
this.shareMode.text = "";
|
||||||
|
|
||||||
|
@ -412,7 +415,9 @@ class PeerUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
html() {
|
html() {
|
||||||
let title = Localization.getTranslation("peer-ui.click-to-send", null, {descriptor: PeerUI._shareMode.descriptor});
|
let title= PeerUI._shareMode.active
|
||||||
|
? Localization.getTranslation("peer-ui.click-to-send-share-mode", null, {descriptor: PeerUI._shareMode.descriptor})
|
||||||
|
: Localization.getTranslation("peer-ui.click-to-send");
|
||||||
|
|
||||||
this.$el.innerHTML = `
|
this.$el.innerHTML = `
|
||||||
<label class="column center pointer" title="${title}">
|
<label class="column center pointer" title="${title}">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue