From 602b16a0efc170a99dbaa27009bbe9037b4912db Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Thu, 31 Oct 2024 21:14:40 -0500 Subject: [PATCH] finish hooking the message into translation --- src/webpage/i18n.ts | 17 +++++++++-------- src/webpage/message.ts | 17 ++++++++--------- src/webpage/translations/en.json | 10 +++++++++- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/webpage/i18n.ts b/src/webpage/i18n.ts index c30ad7b..a7c3052 100644 --- a/src/webpage/i18n.ts +++ b/src/webpage/i18n.ts @@ -57,6 +57,14 @@ class I18n{ } static fillInBlanks(msg:string,params:string[]):string{ //thanks to geotale for the regex + msg=msg.replace(/\$\d+/g,(match) => { + const number=Number(match.slice(1)); + if(params[number-1]){ + return params[number-1]; + }else{ + return match; + } + }); msg=msg.replace(/{{(.+?)}}/g, (str, match:string) => { const [op,strsSplit]=this.fillInBlanks(match,params).split(":"); @@ -86,14 +94,7 @@ class I18n{ return str; } ); - msg=msg.replace(/\$\d+/g,(str, match:string) => { - const number=Number(match); - if(params[number-1]){ - return params[number-1]; - }else{ - return str; - } - }); + return msg; } private static async toTranslation(trans:string|translation,lang:string):Promise{ diff --git a/src/webpage/message.ts b/src/webpage/message.ts index 3ab5480..49b2acd 100644 --- a/src/webpage/message.ts +++ b/src/webpage/message.ts @@ -341,8 +341,7 @@ class Message extends SnowFlake{ if(ignoredblock){ if(premessage?.author !== this.author){ const span = document.createElement("span"); - span.textContent = - "You have this user blocked, click to hide these messages."; + span.textContent = I18n.getTranslation("hideBlockedMessages"); div.append(span); span.classList.add("blocked"); span.onclick = _=>{ @@ -379,7 +378,7 @@ class Message extends SnowFlake{ this.channel.idToNext.get(next.id) as string ); } - span.textContent = `You have this user blocked, click to see the ${count} blocked messages.`; + span.textContent = I18n.getTranslation("showBlockedMessages",count+""); build.append(span); span.onclick = _=>{ const scroll = this.channel.infinite.scrollTop; @@ -595,13 +594,13 @@ class Message extends SnowFlake{ } const diaolog = new Dialog([ "vdiv", - ["title", "Are you sure you want to delete this?"], + ["title", I18n.getTranslation("deleteConfirm")], [ "hdiv", [ "button", "", - "Yes", + I18n.getTranslation("yes"), ()=>{ this.delete(); diaolog.hide(); @@ -610,7 +609,7 @@ class Message extends SnowFlake{ [ "button", "", - "No", + I18n.getTranslation("no"), ()=>{ diaolog.hide(); }, @@ -750,11 +749,11 @@ function formatTime(date: Date){ const formatTime = (date: Date)=>date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); if(datestring === now){ - return`Today at ${formatTime(date)}`; + return I18n.getTranslation("todayAt",formatTime(date)); }else if(datestring === yesterdayStr){ - return`Yesterday at ${formatTime(date)}`; + return I18n.getTranslation("yesterdayAt",formatTime(date)); }else{ - return`${date.toLocaleDateString()} at ${formatTime(date)}`; + return I18n.getTranslation("otherAt",formatTime(date),date.toLocaleDateString(),formatTime(date)); } } let tomorrow = 0; diff --git a/src/webpage/translations/en.json b/src/webpage/translations/en.json index e5b1caa..26a351f 100644 --- a/src/webpage/translations/en.json +++ b/src/webpage/translations/en.json @@ -114,7 +114,15 @@ "SEND_POLLS": "Create polls", "USE_EXTERNAL_APPS": "Use external apps" } - } + }, + "hideBlockedMessages":"You have this user blocked, click to hide these messages.", + "showBlockedMessages":"You have this user blocked, click to see the $1 blocked {{PLURAL:$1|message|messages}}.", + "deleteConfirm":"Are you sure you want to delete this?", + "yes":"Yes", + "no":"No", + "todayAt":"Today at $1", + "yesterdayAt":"Yesterday at $1", + "otherAt":"$1 at $2" }, "ru": "./ru.json" }