finish hooking the message into translation

This commit is contained in:
MathMan05 2024-10-31 21:14:40 -05:00
parent dac1f55a7d
commit 602b16a0ef
3 changed files with 26 additions and 18 deletions

View file

@ -57,6 +57,14 @@ class I18n{
} }
static fillInBlanks(msg:string,params:string[]):string{ static fillInBlanks(msg:string,params:string[]):string{
//thanks to geotale for the regex //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, msg=msg.replace(/{{(.+?)}}/g,
(str, match:string) => { (str, match:string) => {
const [op,strsSplit]=this.fillInBlanks(match,params).split(":"); const [op,strsSplit]=this.fillInBlanks(match,params).split(":");
@ -86,14 +94,7 @@ class I18n{
return str; 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; return msg;
} }
private static async toTranslation(trans:string|translation,lang:string):Promise<translation>{ private static async toTranslation(trans:string|translation,lang:string):Promise<translation>{

View file

@ -341,8 +341,7 @@ class Message extends SnowFlake{
if(ignoredblock){ if(ignoredblock){
if(premessage?.author !== this.author){ if(premessage?.author !== this.author){
const span = document.createElement("span"); const span = document.createElement("span");
span.textContent = span.textContent = I18n.getTranslation("hideBlockedMessages");
"You have this user blocked, click to hide these messages.";
div.append(span); div.append(span);
span.classList.add("blocked"); span.classList.add("blocked");
span.onclick = _=>{ span.onclick = _=>{
@ -379,7 +378,7 @@ class Message extends SnowFlake{
this.channel.idToNext.get(next.id) as string 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); build.append(span);
span.onclick = _=>{ span.onclick = _=>{
const scroll = this.channel.infinite.scrollTop; const scroll = this.channel.infinite.scrollTop;
@ -595,13 +594,13 @@ class Message extends SnowFlake{
} }
const diaolog = new Dialog([ const diaolog = new Dialog([
"vdiv", "vdiv",
["title", "Are you sure you want to delete this?"], ["title", I18n.getTranslation("deleteConfirm")],
[ [
"hdiv", "hdiv",
[ [
"button", "button",
"", "",
"Yes", I18n.getTranslation("yes"),
()=>{ ()=>{
this.delete(); this.delete();
diaolog.hide(); diaolog.hide();
@ -610,7 +609,7 @@ class Message extends SnowFlake{
[ [
"button", "button",
"", "",
"No", I18n.getTranslation("no"),
()=>{ ()=>{
diaolog.hide(); diaolog.hide();
}, },
@ -750,11 +749,11 @@ function formatTime(date: Date){
const formatTime = (date: Date)=>date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); const formatTime = (date: Date)=>date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
if(datestring === now){ if(datestring === now){
return`Today at ${formatTime(date)}`; return I18n.getTranslation("todayAt",formatTime(date));
}else if(datestring === yesterdayStr){ }else if(datestring === yesterdayStr){
return`Yesterday at ${formatTime(date)}`; return I18n.getTranslation("yesterdayAt",formatTime(date));
}else{ }else{
return`${date.toLocaleDateString()} at ${formatTime(date)}`; return I18n.getTranslation("otherAt",formatTime(date),date.toLocaleDateString(),formatTime(date));
} }
} }
let tomorrow = 0; let tomorrow = 0;

View file

@ -114,7 +114,15 @@
"SEND_POLLS": "Create polls", "SEND_POLLS": "Create polls",
"USE_EXTERNAL_APPS": "Use external apps" "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" "ru": "./ru.json"
} }