fix various issues and change translation stuff

This commit is contained in:
MathMan05 2024-11-12 14:40:07 -06:00
parent 71aa1c0e9b
commit 8af8e4dd03
7 changed files with 821 additions and 821 deletions

View file

@ -6,6 +6,7 @@ const argv = require("yargs").argv;
const rimraf = require("rimraf");
const plumber = require("gulp-plumber");
const sourcemaps = require('gulp-sourcemaps');
const fs=require("fs");
const swcOptions = {
jsc: {
parser: {
@ -69,14 +70,21 @@ gulp.task("copy-html", () => {
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist"));
});
gulp.task("copy-translations", () => {
let langs=fs.readdirSync("translations");
langs=langs.filter((e)=>e!=="qqq.json");
const langobj={};
for(const lang of langs){
const json=JSON.parse(fs.readFileSync("translations/"+lang).toString());
langobj[lang]=json.readableName;
}
if(!fs.existsSync("dist/webpage/translations")) fs.mkdirSync("dist/webpage/translations")
fs.writeFileSync("dist/webpage/translations/langs.js",`const langs=${JSON.stringify(langobj)};export{langs}`);
return gulp
.src("translations/*.json")
.pipe(plumber()) // Prevent pipe breaking caused by errors
.pipe(gulp.dest("dist/webpage/translations"));
});
// Task to copy other static assets (e.g., CSS, images)
gulp.task("copy-assets", () => {
return gulp

View file

@ -405,9 +405,7 @@ class Guild extends SnowFlake{
return a.position - b.position;
});
}
static generateGuildIcon(
guild: Guild | (invitejson["guild"] & { info: { cdn: string } })
){
static generateGuildIcon(guild: Guild | (invitejson["guild"] & { info: { cdn: string } })){
const divy = document.createElement("div");
divy.classList.add("servernoti");

View file

@ -1,3 +1,10 @@
//@ts-ignore
import {langs} from "./translations/langs.js";
const langmap=new Map<string,string>();
for(const lang of Object.keys(langs) as string[]){
langmap.set(lang,langs[lang]);
}
console.log(langs);
type translation={
[key:string]:string|translation
};
@ -8,23 +15,13 @@ class I18n{
static done=new Promise<void>((res2,_reject)=>{
res=res2;
});
static async create(json:translation|string,lang:string){
if(typeof json === "string"){
json=await (await fetch(json)).json() as translation;
}
static async create(lang:string){
const json=await (await fetch("/translations/"+lang+".json")).json() as translation;
const translations:translation[]=[];
let translation=json[lang];
if(!translation){
translation=json[lang[0]+lang[1]];
if(!translation){
console.error(lang+" does not exist in the translations");
translation=json["en"];
lang="en";
}
}
translations.push(await this.toTranslation(translation,lang));
translations.push(json);
if(lang!=="en"){
translations.push(await this.toTranslation(json["en"],"en"))
translations.push(await (await fetch("/translations/en.json")).json() as translation);
}
this.lang=lang;
this.translations=translations;
@ -98,24 +95,17 @@ class I18n{
return msg;
}
private static async toTranslation(trans:string|translation,lang:string):Promise<translation>{
if(typeof trans==='string'){
return this.toTranslation((await (await fetch(trans)).json() as translation)[lang],lang);
}else{
return trans;
}
}
static options(){
return ["en","ru","tr"]
return [...langmap.keys()].map(e=>e.replace(".json",""));
}
static setLanguage(lang:string){
if(this.options().indexOf(userLocale)!==-1){
localStorage.setItem("lang",lang);
I18n.create("/translations/en.json",lang);
I18n.create(lang);
}
}
}
console.log(langmap);
let userLocale = navigator.language.slice(0,2) || "en";
if(I18n.options().indexOf(userLocale)===-1){
userLocale="en";
@ -126,6 +116,6 @@ if(storage){
}else{
localStorage.setItem("lang",userLocale)
}
I18n.create("/translations/en.json",userLocale);
I18n.create(userLocale);
export{I18n};

View file

@ -4,6 +4,64 @@ import { I18n } from "./i18n.js";
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
const iOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
const instancefetch=fetch("/instances.json")
.then(res=>res.json())
.then(
(json: {
name: string;
description?: string;
descriptionLong?: string;
image?: string;
url?: string;
display?: boolean;
online?: boolean;
uptime: { alltime: number; daytime: number; weektime: number };
urls: {
wellknown: string;
api: string;
cdn: string;
gateway: string;
login?: string;
}
}[]
)=>{
instances = json;
if(datalist){
console.warn(json);
if(instancein && instancein.value === ""){
instancein.value = json[0].name;
}
for(const instance of json){
if(instance.display === false){
continue;
}
const option = document.createElement("option");
option.disabled = !instance.online;
option.value = instance.name;
if(instance.url){
stringURLMap.set(option.value, instance.url);
if(instance.urls){
stringURLsMap.set(instance.url, instance.urls);
}
}else if(instance.urls){
stringURLsMap.set(option.value, instance.urls);
}else{
option.disabled = true;
}
if(instance.description){
option.label = instance.description;
}else{
option.label = instance.name;
}
datalist.append(option);
}
checkInstance("");
}
}
);
await I18n.done
function setTheme(){
let name = localStorage.getItem("theme");
if(!name){
@ -353,6 +411,7 @@ async function getapiurls(str: string): Promise<
}
}
async function checkInstance(instance?: string){
await instancefetch;
const verify = document.getElementById("verify");
try{
verify!.textContent = I18n.getTranslation("login.checking");
@ -633,58 +692,4 @@ export function getInstances(){
return instances;
}
fetch("/instances.json")
.then(res=>res.json())
.then(
(json: {
name: string;
description?: string;
descriptionLong?: string;
image?: string;
url?: string;
display?: boolean;
online?: boolean;
uptime: { alltime: number; daytime: number; weektime: number };
urls: {
wellknown: string;
api: string;
cdn: string;
gateway: string;
login?: string;
}
}[]
)=>{
instances = json;
if(datalist){
console.warn(json);
if(instancein && instancein.value === ""){
instancein.value = json[0].name;
}
for(const instance of json){
if(instance.display === false){
continue;
}
const option = document.createElement("option");
option.disabled = !instance.online;
option.value = instance.name;
if(instance.url){
stringURLMap.set(option.value, instance.url);
if(instance.urls){
stringURLsMap.set(instance.url, instance.urls);
}
}else if(instance.urls){
stringURLsMap.set(option.value, instance.urls);
}else{
option.disabled = true;
}
if(instance.description){
option.label = instance.description;
}else{
option.label = instance.name;
}
datalist.append(option);
}
checkInstance("");
}
}
);

View file

@ -1,7 +1,7 @@
import { I18n } from "./i18n.js";
import{ checkInstance, adduser }from"./login.js";
import { MarkDown } from "./markdown.js";
await I18n.done
const registerElement = document.getElementById("register");
if(registerElement){
registerElement.addEventListener("submit", registertry);

View file

@ -7,7 +7,8 @@
"locale": "en",
"comment":"Don't know how often I'll update this top part lol"
},
"en": {
"readableName":"English",
"reply": "Reply",
"copyrawtext":"Copy raw text",
"copymessageid":"Copy message id",
@ -376,7 +377,4 @@
"errorReconnect":"Unable to connect to the server, retrying in **$1** seconds...",
"retrying":"Retrying...",
"unableToConnect":"Unable to connect to the Spacebar server. Please try logging out and back in."
},
"ru": "/translations/ru.json",
"tr": "/translations/tr.json"
}

View file

@ -7,7 +7,8 @@
"locale": "tr",
"comment": "Sizli bizli"
},
"tr": {
"readableName":"Türkçe",
"reply": "Yanıtla",
"copyrawtext": "Ham metni kopyala",
"copymessageid": "Mesaj kimliğini kopyala",
@ -370,5 +371,5 @@
"errorReconnect": "Sunucuya bağlanılamadı, **$1** saniye içinde yeniden denenecek...",
"retrying": "Yeniden deneniyor...",
"unableToConnect": "Spacebar sunucusuna bağlanılamıyor. Lütfen çıkış yapıp tekrar deneyin."
}
}