fix various issues and change translation stuff
This commit is contained in:
parent
71aa1c0e9b
commit
8af8e4dd03
7 changed files with 821 additions and 821 deletions
12
gulpfile.cjs
12
gulpfile.cjs
|
@ -6,6 +6,7 @@ const argv = require("yargs").argv;
|
||||||
const rimraf = require("rimraf");
|
const rimraf = require("rimraf");
|
||||||
const plumber = require("gulp-plumber");
|
const plumber = require("gulp-plumber");
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
|
const fs=require("fs");
|
||||||
const swcOptions = {
|
const swcOptions = {
|
||||||
jsc: {
|
jsc: {
|
||||||
parser: {
|
parser: {
|
||||||
|
@ -69,14 +70,21 @@ gulp.task("copy-html", () => {
|
||||||
.pipe(plumber()) // Prevent pipe breaking caused by errors
|
.pipe(plumber()) // Prevent pipe breaking caused by errors
|
||||||
.pipe(gulp.dest("dist"));
|
.pipe(gulp.dest("dist"));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task("copy-translations", () => {
|
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
|
return gulp
|
||||||
.src("translations/*.json")
|
.src("translations/*.json")
|
||||||
.pipe(plumber()) // Prevent pipe breaking caused by errors
|
.pipe(plumber()) // Prevent pipe breaking caused by errors
|
||||||
.pipe(gulp.dest("dist/webpage/translations"));
|
.pipe(gulp.dest("dist/webpage/translations"));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Task to copy other static assets (e.g., CSS, images)
|
// Task to copy other static assets (e.g., CSS, images)
|
||||||
gulp.task("copy-assets", () => {
|
gulp.task("copy-assets", () => {
|
||||||
return gulp
|
return gulp
|
||||||
|
|
|
@ -405,9 +405,7 @@ class Guild extends SnowFlake{
|
||||||
return a.position - b.position;
|
return a.position - b.position;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
static generateGuildIcon(
|
static generateGuildIcon(guild: Guild | (invitejson["guild"] & { info: { cdn: string } })){
|
||||||
guild: Guild | (invitejson["guild"] & { info: { cdn: string } })
|
|
||||||
){
|
|
||||||
const divy = document.createElement("div");
|
const divy = document.createElement("div");
|
||||||
divy.classList.add("servernoti");
|
divy.classList.add("servernoti");
|
||||||
|
|
||||||
|
|
|
@ -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={
|
type translation={
|
||||||
[key:string]:string|translation
|
[key:string]:string|translation
|
||||||
};
|
};
|
||||||
|
@ -8,23 +15,13 @@ class I18n{
|
||||||
static done=new Promise<void>((res2,_reject)=>{
|
static done=new Promise<void>((res2,_reject)=>{
|
||||||
res=res2;
|
res=res2;
|
||||||
});
|
});
|
||||||
static async create(json:translation|string,lang:string){
|
static async create(lang:string){
|
||||||
if(typeof json === "string"){
|
|
||||||
json=await (await fetch(json)).json() as translation;
|
const json=await (await fetch("/translations/"+lang+".json")).json() as translation;
|
||||||
}
|
|
||||||
const translations:translation[]=[];
|
const translations:translation[]=[];
|
||||||
let translation=json[lang];
|
translations.push(json);
|
||||||
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));
|
|
||||||
if(lang!=="en"){
|
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.lang=lang;
|
||||||
this.translations=translations;
|
this.translations=translations;
|
||||||
|
@ -98,24 +95,17 @@ class I18n{
|
||||||
|
|
||||||
return msg;
|
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(){
|
static options(){
|
||||||
return ["en","ru","tr"]
|
return [...langmap.keys()].map(e=>e.replace(".json",""));
|
||||||
}
|
}
|
||||||
static setLanguage(lang:string){
|
static setLanguage(lang:string){
|
||||||
if(this.options().indexOf(userLocale)!==-1){
|
if(this.options().indexOf(userLocale)!==-1){
|
||||||
localStorage.setItem("lang",lang);
|
localStorage.setItem("lang",lang);
|
||||||
I18n.create("/translations/en.json",lang);
|
I18n.create(lang);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(langmap);
|
||||||
let userLocale = navigator.language.slice(0,2) || "en";
|
let userLocale = navigator.language.slice(0,2) || "en";
|
||||||
if(I18n.options().indexOf(userLocale)===-1){
|
if(I18n.options().indexOf(userLocale)===-1){
|
||||||
userLocale="en";
|
userLocale="en";
|
||||||
|
@ -126,6 +116,6 @@ if(storage){
|
||||||
}else{
|
}else{
|
||||||
localStorage.setItem("lang",userLocale)
|
localStorage.setItem("lang",userLocale)
|
||||||
}
|
}
|
||||||
I18n.create("/translations/en.json",userLocale);
|
I18n.create(userLocale);
|
||||||
|
|
||||||
export{I18n};
|
export{I18n};
|
||||||
|
|
|
@ -4,6 +4,64 @@ import { I18n } from "./i18n.js";
|
||||||
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
const mobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
||||||
const iOS = /iPhone|iPad|iPod/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(){
|
function setTheme(){
|
||||||
let name = localStorage.getItem("theme");
|
let name = localStorage.getItem("theme");
|
||||||
if(!name){
|
if(!name){
|
||||||
|
@ -353,6 +411,7 @@ async function getapiurls(str: string): Promise<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function checkInstance(instance?: string){
|
async function checkInstance(instance?: string){
|
||||||
|
await instancefetch;
|
||||||
const verify = document.getElementById("verify");
|
const verify = document.getElementById("verify");
|
||||||
try{
|
try{
|
||||||
verify!.textContent = I18n.getTranslation("login.checking");
|
verify!.textContent = I18n.getTranslation("login.checking");
|
||||||
|
@ -633,58 +692,4 @@ export function getInstances(){
|
||||||
return instances;
|
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("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { I18n } from "./i18n.js";
|
import { I18n } from "./i18n.js";
|
||||||
import{ checkInstance, adduser }from"./login.js";
|
import{ checkInstance, adduser }from"./login.js";
|
||||||
import { MarkDown } from "./markdown.js";
|
import { MarkDown } from "./markdown.js";
|
||||||
|
await I18n.done
|
||||||
const registerElement = document.getElementById("register");
|
const registerElement = document.getElementById("register");
|
||||||
if(registerElement){
|
if(registerElement){
|
||||||
registerElement.addEventListener("submit", registertry);
|
registerElement.addEventListener("submit", registertry);
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"locale": "en",
|
"locale": "en",
|
||||||
"comment":"Don't know how often I'll update this top part lol"
|
"comment":"Don't know how often I'll update this top part lol"
|
||||||
},
|
},
|
||||||
"en": {
|
"readableName":"English",
|
||||||
|
|
||||||
"reply": "Reply",
|
"reply": "Reply",
|
||||||
"copyrawtext":"Copy raw text",
|
"copyrawtext":"Copy raw text",
|
||||||
"copymessageid":"Copy message id",
|
"copymessageid":"Copy message id",
|
||||||
|
@ -376,7 +377,4 @@
|
||||||
"errorReconnect":"Unable to connect to the server, retrying in **$1** seconds...",
|
"errorReconnect":"Unable to connect to the server, retrying in **$1** seconds...",
|
||||||
"retrying":"Retrying...",
|
"retrying":"Retrying...",
|
||||||
"unableToConnect":"Unable to connect to the Spacebar server. Please try logging out and back in."
|
"unableToConnect":"Unable to connect to the Spacebar server. Please try logging out and back in."
|
||||||
},
|
|
||||||
"ru": "/translations/ru.json",
|
|
||||||
"tr": "/translations/tr.json"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
"locale": "tr",
|
"locale": "tr",
|
||||||
"comment": "Sizli bizli"
|
"comment": "Sizli bizli"
|
||||||
},
|
},
|
||||||
"tr": {
|
"readableName":"Türkçe",
|
||||||
|
|
||||||
"reply": "Yanıtla",
|
"reply": "Yanıtla",
|
||||||
"copyrawtext": "Ham metni kopyala",
|
"copyrawtext": "Ham metni kopyala",
|
||||||
"copymessageid": "Mesaj kimliğini kopyala",
|
"copymessageid": "Mesaj kimliğini kopyala",
|
||||||
|
@ -370,5 +371,5 @@
|
||||||
"errorReconnect": "Sunucuya bağlanılamadı, **$1** saniye içinde yeniden denenecek...",
|
"errorReconnect": "Sunucuya bağlanılamadı, **$1** saniye içinde yeniden denenecek...",
|
||||||
"retrying": "Yeniden deneniyor...",
|
"retrying": "Yeniden deneniyor...",
|
||||||
"unableToConnect": "Spacebar sunucusuna bağlanılamıyor. Lütfen çıkış yapıp tekrar deneyin."
|
"unableToConnect": "Spacebar sunucusuna bağlanılamıyor. Lütfen çıkış yapıp tekrar deneyin."
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue