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
|
@ -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");
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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("");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue