finish hooking the message into translation
This commit is contained in:
parent
dac1f55a7d
commit
602b16a0ef
3 changed files with 26 additions and 18 deletions
|
@ -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<translation>{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue